]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/extsearch.t
isearch: emulate per-inbox search with ->ALL
[public-inbox.git] / t / extsearch.t
index f9f74e5c9db3ad6cf1cb06a477ff3dcb94a28bb3..97786b21df35d195774fbb2e9e6d663f7093362b 100644 (file)
@@ -16,7 +16,8 @@ my $host_port = $sock->sockhost . ':' . $sock->sockport;
 my ($home, $for_destroy) = tmpdir();
 local $ENV{HOME} = $home;
 mkdir "$home/.public-inbox" or BAIL_OUT $!;
-open my $fh, '>', "$home/.public-inbox/config" or BAIL_OUT $!;
+my $cfg_path = "$home/.public-inbox/config";
+open my $fh, '>', $cfg_path or BAIL_OUT $!;
 print $fh <<EOF or BAIL_OUT $!;
 [publicinboxMda]
        spamcheck = none
@@ -52,10 +53,13 @@ run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
 run_script(['-index', "$home/v1test"]) or BAIL_OUT "index $?";
 
 ok(run_script([qw(-extindex --all), "$home/extindex"]), 'extindex init');
-
+{
+       my $es = PublicInbox::ExtSearch->new("$home/extindex");
+       ok($es->has_threadid, '->has_threadid');
+}
 
 { # TODO: -extindex should write this to config
-       open $fh, '>>', "$home/.public-inbox/config" or BAIL_OUT $!;
+       open $fh, '>>', $cfg_path or BAIL_OUT $!;
        print $fh <<EOF or BAIL_OUT $!;
 ; for ->ALL
 [extindex "all"]
@@ -68,15 +72,18 @@ EOF
        ok($pi_cfg->ALL, '->ALL');
        my $ibx = $pi_cfg->{-by_newsgroup}->{'v2.example'};
        my $ret = $pi_cfg->ALL->nntp_xref_for($ibx, $ibx->over->get_art(1));
-       is_deeply($ret, ['v1.example:1'], '->nntp_xref_for');
+       is_deeply($ret, { 'v1.example' => 1, 'v2.example' => 1 },
+               '->nntp_xref_for');
 }
 
 SKIP: {
        require_mods(qw(Net::NNTP), 1);
        my ($out, $err) = ("$home/nntpd.out.log", "$home/nntpd.err.log");
-       my $cmd = [ '-nntpd', '-W0' ]; #, "--stdout=$out", "--stderr=$err" ];
+       my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        my $td = start_script($cmd, undef, { 3 => $sock });
        my $n = Net::NNTP->new($host_port);
+       my @xp = $n->xpath('<testmessage@example.com>');
+       is_deeply(\@xp, [ qw(v1.example/1 v2.example/1) ]);
        $n->group('v1.example');
        my $res = $n->head(1);
        @$res = grep(/^Xref: /, @$res);
@@ -118,6 +125,49 @@ my $es = PublicInbox::ExtSearch->new("$home/extindex");
        is(scalar(@$x1), 1, 'original only has one xref3');
        is(scalar(@$x2), 1, 'new message has one xref3');
        isnt($x1->[0], $x2->[0], 'xref3 differs');
+
+       my $mset = $es->mset('b:"BEST MSG"');
+       is($mset->size, 1, 'new message found');
+       $mset = $es->mset('b:"test message"');
+       is($mset->size, 1, 'old message found');
+       delete @$es{qw(git over xdb)}; # fork preparation
+
+       my $pi_cfg = PublicInbox::Config->new;
+       $pi_cfg->fill_all;
+       is(scalar($pi_cfg->ALL->mset('s:Testing')->items), 2,
+               '2 results in ->ALL');
+       my $res = {};
+       my $nr = 0;
+       $pi_cfg->each_inbox(sub {
+               $nr++;
+               my ($ibx) = @_;
+               local $SIG{__WARN__} = sub {}; # FIXME support --reindex
+               my $mset = $ibx->isrch->mset('s:Testing');
+               $res->{$ibx->eidx_key} = $ibx->isrch->mset_to_smsg($ibx, $mset);
+       });
+       is($nr, 2, 'two inboxes');
+       my $exp = {};
+       for my $v (qw(v1 v2)) {
+               my $ibx = $pi_cfg->lookup_newsgroup("$v.example");
+               my $smsg = $ibx->over->get_art(1);
+               $smsg->psgi_cull;
+               $exp->{"$v.example"} = [ $smsg ];
+       }
+       is_deeply($res, $exp, 'isearch limited results');
+       $pi_cfg = $res = $exp = undef;
+
+       open my $rmfh, '+>', undef or BAIL_OUT $!;
+       $rmfh->autoflush(1);
+       print $rmfh $eml2->as_string or BAIL_OUT $!;
+       seek($rmfh, 0, SEEK_SET) or BAIL_OUT $!;
+       $opt->{0} = $rmfh;
+       ok(run_script([qw(-learn rm --all)], undef, $opt), '-learn rm');
+
+       ok(run_script([qw(-extindex --all), "$home/extindex"], undef, undef),
+               'extindex after rm');
+       is($es->over->get_art(2), undef, 'doc #2 gone');
+       $mset = $es->mset('b:"BEST MSG"');
+       is($mset->size, 0, 'new message gone');
 }
 
 my $misc = $es->misc;
@@ -126,4 +176,18 @@ is(scalar(@it), 2, 'two inboxes');
 like($it[0]->get_document->get_data, qr/v2test/, 'docdata matched v2');
 like($it[1]->get_document->get_data, qr/v1test/, 'docdata matched v1');
 
+if ('remove v1test and test gc') {
+       xsys([qw(git config --unset publicinbox.v1test.inboxdir)],
+               { GIT_CONFIG => $cfg_path });
+       my $opt = { 2 => \(my $err = '') };
+       ok(run_script([qw(-extindex --gc), "$home/extindex"], undef, $opt),
+               'extindex --gc');
+       like($err, qr/^I: remove #1 v1\.example /ms, 'removed v1 message');
+       is(scalar(grep(!/^I:/, split(/^/m, $err))), 0,
+               'no non-informational messages');
+       $misc->{xdb}->reopen;
+       @it = $misc->mset('')->items;
+       is(scalar(@it), 1, 'only one inbox left');
+}
+
 done_testing;