X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fover.t;h=8bf64ecb30aa1e73e1ccf4a2716d920aa4277d1f;hb=5f6a0d2342323541e44ff2f1e7329053d0263800;hp=1d3f9b37ac2b5acc6c91c5207f40725a2717f6e9;hpb=35ff6bb106909b1c1232666a9792156dfa398ea8;p=public-inbox.git diff --git a/t/over.t b/t/over.t index 1d3f9b37..8bf64ecb 100644 --- a/t/over.t +++ b/t/over.t @@ -1,18 +1,17 @@ -# Copyright (C) 2018 all contributors +# Copyright (C) 2018-2020 all contributors # License: AGPL-3.0+ use strict; use warnings; use Test::More; -use File::Temp qw/tempdir/; -foreach my $mod (qw(DBD::SQLite)) { - eval "require $mod"; - plan skip_all => "$mod missing for over.t" if $@; -} - +use Compress::Zlib qw(compress); +use PublicInbox::TestCommon; +require_mods('DBD::SQLite'); use_ok 'PublicInbox::OverIdx'; -my $tmpdir = tempdir('pi-over-XXXXXX', TMPDIR => 1, CLEANUP => 1); +my ($tmpdir, $for_destroy) = tmpdir(); my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3"); $over->connect; +is($over->max, 0, 'max is zero on new DB (scalar context)'); +is_deeply([$over->max], [0], 'max is zero on new DB (list context)'); my $x = $over->next_tid; is(int($x), $x, 'integer tid'); my $y = $over->next_tid; @@ -21,10 +20,15 @@ is($y, $x+1, 'tid increases'); $x = $over->sid('hello-world'); is(int($x), $x, 'integer sid'); $y = $over->sid('hello-WORLD'); -is($y, $x+1, 'sid ncreases'); +is($y, $x+1, 'sid increases'); is($over->sid('hello-world'), $x, 'idempotent'); +ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly'); $over->disconnect; +$over = PublicInbox::Over->new("$tmpdir/over.sqlite3"); +$over->connect; +ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly'); + $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3"); $over->connect; is($over->sid('hello-world'), $x, 'idempotent across reopen'); @@ -35,4 +39,40 @@ is(int($x), $x, 'integer tid for ghost'); $y = $over->create_ghost('NEVAR'); is($y, $x + 1, 'integer tid for ghost increases'); +my $ddd = compress(''); +my $msg = sub { { ts => 0, ds => 0, num => $_[0] } }; +foreach my $s ('', undef) { + $over->add_over($msg->(98), [ 'a' ], [], $s, $ddd); + $over->add_over($msg->(99), [ 'b' ], [], $s, $ddd); + my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ]; + is_deeply([98], $msgs, + 'messages not linked by empty subject'); +} + +$over->add_over($msg->(98), [ 'a' ], [], 's', $ddd); +$over->add_over($msg->(99), [ 'b' ], [], 's', $ddd); +foreach my $mid (qw(a b)) { + my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ]; + is_deeply([98, 99], $msgs, 'linked messages by subject'); +} +$over->add_over($msg->(98), [ 'a' ], [], 's', $ddd); +$over->add_over($msg->(99), [ 'b' ], ['a'], 'diff', $ddd); +foreach my $mid (qw(a b)) { + my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ]; + is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>"); +} +isnt($over->max, 0, 'max is non-zero'); + +$over->rollback_lazy; + +# L +my $v = eval 'v'.$over->{dbh}->{sqlite_version}; +SKIP: { + skip("no WAL in SQLite version $v < 3.7.0", 1) if $v lt v3.7.0; + $over->{dbh}->do('PRAGMA journal_mode = WAL'); + $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3"); + is($over->connect->selectrow_array('PRAGMA journal_mode'), 'wal', + 'WAL journal_mode not clobbered if manually set'); +} + done_testing();