]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/v2reindex.t
lazy load Xapian and make it optional for v2
[public-inbox.git] / t / v2reindex.t
index 3d217aff3c72067f8d57f3c87d7a569efd0a82b1..2a6fc555793d686119892c1a0082d1f07e39fbdd 100644 (file)
@@ -7,6 +7,8 @@ use PublicInbox::MIME;
 use PublicInbox::ContentId qw(content_digest);
 use File::Temp qw/tempdir/;
 use File::Path qw(remove_tree);
+require './t/common.perl';
+require_git(2.6);
 
 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
        eval "require $mod";
@@ -21,6 +23,13 @@ my $ibx_config = {
        -primary_address => 'test@example.com',
        indexlevel => 'full',
 };
+my $agpl = eval {
+       open my $fh, '<', 'COPYING' or die "can't open COPYING: $!";
+       local $/;
+       <$fh>;
+};
+$agpl or die "AGPL or die :P\n";
+my $phrase = q("defending all users' freedom");
 my $mime = PublicInbox::MIME->create(
        header => [
                From => 'a@example.com',
@@ -28,16 +37,15 @@ my $mime = PublicInbox::MIME->create(
                Subject => 'this is a subject',
                Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
        ],
-       body => "hello world\n",
+       body => $agpl,
 );
-local $ENV{NPROC} = 2;
 my $minmax;
 my $msgmap;
 my ($mark1, $mark2, $mark3, $mark4);
 {
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
+       my $im = PublicInbox::V2Writable->new($ibx, {nproc => 1});
        my $im0 = $im->importer();
        foreach my $i (1..10) {
                $mime->header_set('Message-Id', "<$i\@example.com>");
@@ -60,6 +68,7 @@ my ($mark1, $mark2, $mark3, $mark4);
        $minmax = [ $ibx->mm->minmax ];
        ok(defined $minmax->[0] && defined $minmax->[1], 'minmax defined');
        is_deeply($minmax, [ 1, 10 ], 'minmax as expected');
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
 
        my ($min, $max) = @$minmax;
        $msgmap = $ibx->mm->msg_range(\$min, $max);
@@ -85,6 +94,7 @@ my ($mark1, $mark2, $mark3, $mark4);
 
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
 
        my ($min, $max) = $ibx->mm->minmax;
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
@@ -104,6 +114,7 @@ ok(!-d $xap, 'Xapian directories removed');
 
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
 
        my ($min, $max) = $ibx->mm->minmax;
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
@@ -125,6 +136,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        ok(-d $xap, 'Xapian directories recreated');
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
 
        my ($min, $max) = $ibx->mm->minmax;
        is_deeply($ibx->mm->msg_range(\$min, $max), $msgmap, 'msgmap unchanged');
@@ -147,7 +159,8 @@ ok(!-d $xap, 'Xapian directories removed again');
        ok(-d $xap, 'Xapian directories recreated');
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
-       my $mset = $ibx->search->query('"hello world"', {mset=>1});
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+       my $mset = $ibx->search->query($phrase, {mset=>1});
        isnt($mset->size, 0, "phrase search succeeds on indexlevel=full");
        for (<"$xap/*/*">) { $sizes{$ibx->{indexlevel}} += -s _ if -f $_ }
 
@@ -172,18 +185,21 @@ ok(!-d $xap, 'Xapian directories removed again');
        ok(-d $xap, 'Xapian directories recreated');
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
 
        if (0) {
                # not sure why, but Xapian seems to fallback to terms and
                # phrase searches still work
                delete $ibx->{search};
-               my $mset = $ibx->search->query('"hello world"', {mset=>1});
+               my $mset = $ibx->search->query($phrase, {mset=>1});
                is($mset->size, 0, 'phrase search does not work on medium');
        }
-
-       my $mset = $ibx->search->query('hello world', {mset=>1});
+       my $words = $phrase;
+       $words =~ tr/"'//d;
+       my $mset = $ibx->search->query($words, {mset=>1});
        isnt($mset->size, 0, "normal search works on indexlevel=medium");
        for (<"$xap/*/*">) { $sizes{$ibx->{indexlevel}} += -s _ if -f $_ }
+
        ok($sizes{full} > $sizes{medium}, 'medium is smaller than full');
 
 
@@ -208,8 +224,10 @@ ok(!-d $xap, 'Xapian directories removed again');
        ok(-d $xap, 'Xapian directories recreated');
        delete $ibx->{mm};
        is_deeply([ $ibx->mm->minmax ], $minmax, 'minmax unchanged');
-       my $mset = $ibx->search->query('hello', {mset=>1});
-       is($mset->size, 0, "search fails on indexlevel='basic'");
+       is($ibx->mm->num_highwater, 10, 'num_highwater as expected');
+
+       isnt($ibx->search, 'no search for basic');
+
        for (<"$xap/*/*">) { $sizes{$ibx->{indexlevel}} += -s _ if -f $_ }
        ok($sizes{medium} > $sizes{basic}, 'basic is smaller than medium');