]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/v2reindex.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / v2reindex.t
index ea2b24e59bf894335bf3e98cf7c1309e57c9d85c..cafe8648d1e8b0dd1275f6af884585402e5aee70 100644 (file)
@@ -1,12 +1,9 @@
-# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use warnings;
-use Test::More;
+use strict; use v5.10.1; use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use PublicInbox::ContentHash qw(content_digest);
 use File::Path qw(remove_tree);
-use PublicInbox::TestCommon;
 require_git(2.6);
 require_mods(qw(DBD::SQLite Search::Xapian));
 use_ok 'PublicInbox::V2Writable';
@@ -18,6 +15,7 @@ my $ibx_config = {
        version => 2,
        -primary_address => 'test@example.com',
        indexlevel => 'full',
+       -no_fsync => 1,
 };
 my $agpl = do {
        open my $fh, '<', 'COPYING' or die "can't open COPYING: $!";
@@ -153,7 +151,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
        is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
-       my $mset = $ibx->search->query($phrase, {mset=>1});
+       my $mset = $ibx->search->mset($phrase);
        isnt($mset->size, 0, "phrase search succeeds on indexlevel=full");
        for (glob("$xap/*/*")) { $sizes{$ibx->{indexlevel}} += -s _ if -f $_ }
 
@@ -184,12 +182,12 @@ ok(!-d $xap, 'Xapian directories removed again');
                # not sure why, but Xapian seems to fallback to terms and
                # phrase searches still work
                delete $ibx->{search};
-               my $mset = $ibx->search->query($phrase, {mset=>1});
+               my $mset = $ibx->search->mset($phrase);
                is($mset->size, 0, 'phrase search does not work on medium');
        }
        my $words = $phrase;
        $words =~ tr/"'//d;
-       my $mset = $ibx->search->query($words, {mset=>1});
+       my $mset = $ibx->search->mset($words);
        isnt($mset->size, 0, "normal search works on indexlevel=medium");
        for (glob("$xap/*/*")) { $sizes{$ibx->{indexlevel}} += -s _ if -f $_ }
 
@@ -432,7 +430,7 @@ my $check_rethread = sub {
        my $ibx = PublicInbox::Inbox->new(\%config);
        my $f = $ibx->over->{dbh}->sqlite_db_filename;
        my $over = PublicInbox::OverIdx->new($f);
-       my $dbh = $over->connect;
+       my $dbh = $over->dbh;
        my $non_ghost_tids = sub {
                $dbh->selectall_arrayref(<<'');
 SELECT tid FROM over WHERE num > 0 ORDER BY tid ASC
@@ -531,7 +529,8 @@ EOF
 
        my %uniq;
        for my $s (qw(uno dos tres)) {
-               my $msgs = $ibx->search->query("s:$s");
+               my $mset = $ibx->search->mset("s:$s");
+               my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
                is(scalar(@$msgs), 1, "only one result for `$s'");
                $uniq{$msgs->[0]->{num}}++;
        }
@@ -542,4 +541,17 @@ EOF
 $check_rethread->('3-headed-monster once');
 $check_rethread->('3-headed-monster twice');
 
+my $rdr = { 2 => \(my $err = '') };
+my $env = { PI_CONFIG => '/dev/null' };
+ok(run_script([qw(-index --reindex --xapian-only), $inboxdir], $env, $rdr),
+       '--xapian-only works');
+is($err, '', 'no errors from --xapian-only');
+undef $for_destroy;
+SKIP: {
+       skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux';
+       my $lsof = require_cmd('lsof', 1) or skip 'no lsof in PATH', 1;
+       my $rdr = { 2 => \(my $null_err) };
+       my @d = grep(m!/xap[0-9]+/!, xqx([$lsof, '-p', $$], undef, $rdr));
+       is_deeply(\@d, [], 'no deleted index files') or diag explain(\@d);
+}
 done_testing();