about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/cindex.t25
-rw-r--r--t/extsearch.t9
-rw-r--r--t/imap_searchqp.t15
-rw-r--r--t/psgi_v2.t54
-rw-r--r--t/www_altid.t24
-rw-r--r--t/xap_helper.t44
6 files changed, 127 insertions, 44 deletions
diff --git a/t/cindex.t b/t/cindex.t
index e5f26ec3..0ae0b2b4 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -6,7 +6,7 @@ use PublicInbox::TestCommon;
 use Cwd qw(getcwd);
 use List::Util qw(sum);
 use autodie qw(close mkdir open rename);
-require_mods(qw(json Xapian +SCM_RIGHTS));
+require_mods(qw(json Xapian +SCM_RIGHTS DBD::SQLite));
 use_ok 'PublicInbox::CodeSearchIdx';
 use PublicInbox::Import;
 my ($tmp, $for_destroy) = tmpdir();
@@ -147,26 +147,28 @@ if ('multi-repo search') {
 
 my $test_xhc = sub {
         my ($xhc) = @_;
+        my $csrch = PublicInbox::CodeSearch->new("$tmp/ext");
         my $impl = $xhc->{impl};
         my ($r, @l);
-        $r = $xhc->mkreq([], qw(mset -D -c -g), $zp_git, @xh_args, 'NUL');
+        $r = $xhc->mkreq([], qw(mset -c -g), $zp_git, @xh_args, 'NUL');
         chomp(@l = <$r>);
-        is(shift(@l), 'mset.size=2', "got expected header $impl");
+        like shift(@l), qr/\bmset\.size=2\b/, "got expected header $impl";
         my %docid2data;
         my @got = sort map {
-                my @f = split /\0/;
-                is scalar(@f), 2, 'got 2 entries';
-                $docid2data{$f[0]} = $f[1];
-                $f[1];
+                my ($docid, $pct, $rank, @extra) = split /\0/;
+                ok $pct >= 0 && $pct <= 100, 'pct in range';
+                ok $rank >= 0 && $rank <= 100000, 'rank ok';
+                is scalar(@extra), 0, 'no extra fields';
+                $docid2data{$docid} =
+                        $csrch->xdb->get_document($docid)->get_data;
         } @l;
         is_deeply(\@got, $exp, "expected doc_data $impl");
 
         $r = $xhc->mkreq([], qw(mset -c -g), "$tmp/wt0/.git", @xh_args, 'NUL');
         chomp(@l = <$r>);
-        is(shift(@l), 'mset.size=0', "got miss in wrong dir $impl");
+        like shift(@l), qr/\bmset.size=0\b/, "got miss in wrong dir $impl";
         is_deeply(\@l, [], "no extra lines $impl");
 
-        my $csrch = PublicInbox::CodeSearch->new("$tmp/ext");
         while (my ($did, $expect) = each %docid2data) {
                 is_deeply($csrch->xdb->get_document($did)->get_data,
                         $expect, "docid=$did data matches");
@@ -179,14 +181,15 @@ SKIP: {
         require_mods('+SCM_RIGHTS', 1);
         require PublicInbox::XapClient;
         my $xhc = PublicInbox::XapClient::start_helper('-j0');
-        $test_xhc->($xhc);
+        my $csrch = PublicInbox::CodeSearch->new("$tmp/ext");
+        $test_xhc->($xhc, $csrch);
         skip 'PI_NO_CXX set', 1 if $ENV{PI_NO_CXX};
         $xhc->{impl} =~ /Cxx/ or
                 skip 'C++ compiler or xapian development libs missing', 1;
         skip 'TEST_XH_CXX_ONLY set', 1 if $ENV{TEST_XH_CXX_ONLY};
         local $ENV{PI_NO_CXX} = 1; # force XS or SWIG binding test
         $xhc = PublicInbox::XapClient::start_helper('-j0');
-        $test_xhc->($xhc);
+        $test_xhc->($xhc, $csrch);
 }
 
 if ('--update') {
diff --git a/t/extsearch.t b/t/extsearch.t
index 090f6db5..797aa8f5 100644
--- a/t/extsearch.t
+++ b/t/extsearch.t
@@ -559,6 +559,15 @@ EOM
         for (@xdb) {
                 ok(!$_->get_metadata('indexlevel'), 'no indexlevel in >0 shard')
         }
+        my $mpi = "$d/ALL.git/objects/pack/multi-pack-index";
+        SKIP: {
+                skip 'git too old for for multi-pack-index', 2 if !-f $mpi;
+                unlink glob("$d/ALL.git/objects/pack/*");
+                ok run_script([qw(-extindex --all -L medium -j3
+                                --no-multi-pack-index), $d]),
+                                'test --no-multi-pack-index';
+                ok !-f $mpi, '--no-multi-pack-index respected';
+        }
 }
 
 test_lei(sub {
diff --git a/t/imap_searchqp.t b/t/imap_searchqp.t
index ff1b4535..d7840dd0 100644
--- a/t/imap_searchqp.t
+++ b/t/imap_searchqp.t
@@ -3,6 +3,8 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
+use autodie qw(open seek read);
+use Fcntl qw(SEEK_SET);
 use Time::Local qw(timegm);
 use PublicInbox::TestCommon;
 require_mods(qw(-imapd));
@@ -29,12 +31,15 @@ is($q->{xap}, 'f:"b"', 'charset handled');
 $q = $parse->(qq{CHARSET WTF-8 From b});
 like($q, qr/\ANO \[/, 'bad charset rejected');
 
-for my $x ('', ' (try #2)') {
-        open my $fh, '>:scalar', \(my $buf = '') or die;
-        local *STDERR = $fh;
+{
+        open my $tmperr, '+>', undef;
+        open my $olderr, '>&', \*STDERR;
+        open STDERR, '>&', $tmperr;
         $q = $parse->(qq{CHARSET});
-        last if is($buf, '', "nothing spewed to STDERR on bad query$x");
-        diag 'FIXME: above fails mysteriously sometimes, so we try again...';
+        open STDERR, '>&', $olderr;
+        seek $tmperr, 0, SEEK_SET;
+        read($tmperr, my $buf, -s $tmperr);
+        is($buf, '', 'nothing spewed to STDERR on bad query');
 }
 
 like($q, qr/\ABAD /, 'bad charset rejected');
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index d5c328f0..2b678fd8 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -9,6 +9,7 @@ require_git(2.6);
 use PublicInbox::Eml;
 use PublicInbox::Config;
 use PublicInbox::MID qw(mids);
+use autodie qw(kill rename);
 require_mods(qw(DBD::SQLite Xapian HTTP::Request::Common Plack::Test
                 URI::Escape Plack::Builder HTTP::Date));
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
@@ -394,4 +395,57 @@ my $client3 = sub {
 test_psgi(sub { $www->call(@_) }, $client3);
 test_httpd($env, $client3, 4);
 
+if ($^O eq 'linux' && -r "/proc/$$/stat") {
+        my $args;
+        my $search_xh_pid = sub {
+                my ($pid) = @_;
+                for my $f (glob('/proc/*/stat')) {
+                        open my $fh, '<', $f or next;
+                        my @s = split /\s+/, readline($fh) // next;
+                        next if $s[3] ne $pid; # look for matching PPID
+                        open $fh, '<', "/proc/$s[0]/cmdline" or next;
+                        my $cmdline = readline($fh) // next;
+                        if ($cmdline =~ /\0-MPublicInbox::XapHelper\0-e\0/ ||
+                                        $cmdline =~ m!/xap_helper\0!) {
+                                return $s[0];
+                        }
+                }
+                undef;
+        };
+        my $usr1_test = sub {
+                my ($cb) = @_;
+                my $td = $PublicInbox::TestCommon::CURRENT_DAEMON;
+                my $pid = $td->{pid};
+                my $res = $cb->(GET('/v2test/?q=m:a-mid@b'));
+                is $res->code, 200, '-httpd is running w/ search';
+
+                $search_xh_pid->($pid);
+                my $xh_pid = $search_xh_pid->($pid) or
+                        BAIL_OUT "can't find XH pid with $args";
+                my $xh_err = readlink "/proc/$xh_pid/fd/2";
+                is $xh_err, "$env->{TMPDIR}/stderr.log",
+                        "initial stderr expected ($args)";
+                rename "$env->{TMPDIR}/stderr.log",
+                        "$env->{TMPDIR}/stderr.old";
+                $xh_err = readlink "/proc/$xh_pid/fd/2";
+                is $xh_err, "$env->{TMPDIR}/stderr.old",
+                        "stderr followed rename ($args)";
+                kill 'USR1', $pid;
+                tick;
+                $res = $cb->(GET('/v2test/?q=m:a-mid@b'));
+                is $res->code, 200, '-httpd still running w/ search';
+                my $new_xh_pid = $search_xh_pid->($pid) or
+                        BAIL_OUT "can't find new XH pid with $args";
+                is $new_xh_pid, $xh_pid, "XH pid unchanged ($args)";
+                $xh_err = readlink "/proc/$new_xh_pid/fd/2";
+                is $xh_err, "$env->{TMPDIR}/stderr.log",
+                        "stderr updated ($args)";
+        };
+        for my $x ('-X0', '-X1', '-X0 -W1', '-X1 -W1') {
+                $args = $x;
+                local $ENV{TEST_DAEMON_XH} = $args;
+                test_httpd($env, $usr1_test);
+        }
+}
+
 done_testing;
diff --git a/t/www_altid.t b/t/www_altid.t
index de1e6ed6..7ad4a1d2 100644
--- a/t/www_altid.t
+++ b/t/www_altid.t
@@ -6,7 +6,7 @@ use PublicInbox::Config;
 use PublicInbox::Spawn qw(spawn);
 require_cmd('sqlite3');
 require_mods(qw(DBD::SQLite HTTP::Request::Common Plack::Test URI::Escape
-        Plack::Builder IO::Uncompress::Gunzip));
+        Plack::Builder IO::Uncompress::Gunzip Xapian));
 use_ok($_) for qw(Plack::Test HTTP::Request::Common);
 require_ok 'PublicInbox::Msgmap';
 require_ok 'PublicInbox::AltId';
@@ -14,17 +14,13 @@ require_ok 'PublicInbox::WWW';
 my ($tmpdir, $for_destroy) = tmpdir();
 my $aid = 'xyz';
 my $cfgpath;
-my $ibx = create_inbox 'test', indexlevel => 'basic', sub {
+my $spec = "serial:$aid:file=blah.sqlite3";
+my $ibx = create_inbox 'test-altid', indexlevel => 'medium',
+                altid => [ $spec ], sub {
         my ($im, $ibx) = @_;
-        $im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
-From: a@example.com
-Message-Id: <a@example.com>
-
-EOF
-        # $im->done;
-        my $spec = "serial:$aid:file=blah.sqlite3";
         my $altid = PublicInbox::AltId->new($ibx, $spec, 1);
         $altid->mm_alt->mid_set(1, 'a@example.com');
+        undef $altid;
         $cfgpath = "$ibx->{inboxdir}/cfg";
         open my $fh, '>', $cfgpath or BAIL_OUT "open $cfgpath: $!";
         print $fh <<EOF or BAIL_OUT $!;
@@ -35,6 +31,11 @@ EOF
         url = http://example.com/test
 EOF
         close $fh or BAIL_OUT $!;
+        $im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
+From: a@example.com
+Message-Id: <a@example.com>
+
+EOF
 };
 $cfgpath //= "$ibx->{inboxdir}/cfg";
 my $cfg = PublicInbox::Config->new($cfgpath);
@@ -56,6 +57,11 @@ my $client = sub {
         is($mm_cmp->mid_for(1), 'a@example.com', 'sqlite3 dump valid');
         $mm_cmp = undef;
         unlink $cmpfile or die;
+
+        $res = $cb->(GET('/test/?q=xyz:1'));
+        is $res->code, 200, 'altid search hit';
+        $res = $cb->(GET('/test/?q=xyz:10'));
+        is $res->code, 404, 'altid search miss';
 };
 test_psgi(sub { $www->call(@_) }, $client);
 SKIP: {
diff --git a/t/xap_helper.t b/t/xap_helper.t
index 0f474608..78be8539 100644
--- a/t/xap_helper.t
+++ b/t/xap_helper.t
@@ -9,6 +9,7 @@ use Socket qw(AF_UNIX SOCK_SEQPACKET SOCK_STREAM);
 require PublicInbox::AutoReap;
 use PublicInbox::IPC;
 require PublicInbox::XapClient;
+use PublicInbox::DS qw(now);
 use autodie;
 my ($tmp, $for_destroy) = tmpdir();
 
@@ -204,44 +205,35 @@ for my $n (@NO_CXX) {
         $err = do { local $/; <$err_r> };
         is $err, "mset.size=6 nr_out=5\n", "got expected status ($xhc->{impl})";
 
-        $r = $xhc->mkreq([], qw(mset -p -A XDFID -A Q), @ibx_shard_args,
+        $r = $xhc->mkreq([], qw(mset), @ibx_shard_args,
                                 'dfn:lib/PublicInbox/Search.pm');
         chomp((my $hdr, @res) = readline($r));
-        is $hdr, 'mset.size=1', "got expected header via mset ($xhc->{impl}";
+        like $hdr, qr/\bmset\.size=1\b/,
+                "got expected header via mset ($xhc->{impl}";
         is scalar(@res), 1, 'got one result';
         @res = split /\0/, $res[0];
         {
                 my $doc = $v2->search->xdb->get_document($res[0]);
+                ok $doc, 'valid document retrieved';
                 my @q = PublicInbox::Search::xap_terms('Q', $doc);
                 is_deeply \@q, [ $mid ], 'docid usable';
         }
         ok $res[1] > 0 && $res[1] <= 100, 'pct > 0 && <= 100';
-        is $res[2], 'XDFID'.$dfid, 'XDFID result matches';
-        is $res[3], 'Q'.$mid, 'Q (msgid) mset result matches';
-        is scalar(@res), 4, 'only 4 columns in result';
+        is scalar(@res), 3, 'only 3 columns in result';
 
-        $r = $xhc->mkreq([], qw(mset -p -A XDFID -A Q), @ibx_shard_args,
+        $r = $xhc->mkreq([], qw(mset), @ibx_shard_args,
                                 'dt:19700101'.'000000..');
         chomp(($hdr, @res) = readline($r));
-        is $hdr, 'mset.size=6',
+        like $hdr, qr/\bmset\.size=6\b/,
                 "got expected header via multi-result mset ($xhc->{impl}";
         is(scalar(@res), 6, 'got 6 rows');
         for my $r (@res) {
-                my ($docid, $pct, @rest) = split /\0/, $r;
+                my ($docid, $pct, $rank, @rest) = split /\0/, $r;
                 my $doc = $v2->search->xdb->get_document($docid);
                 ok $pct > 0 && $pct <= 100,
                         "pct > 0 && <= 100 #$docid ($xhc->{impl})";
-                my %terms;
-                for (@rest) {
-                        s/\A([A-Z]+)// or xbail 'no prefix=', \@rest;
-                        push @{$terms{$1}}, $_;
-                }
-                while (my ($pfx, $vals) = each %terms) {
-                        @$vals = sort @$vals;
-                        my @q = PublicInbox::Search::xap_terms($pfx, $doc);
-                        is_deeply $vals, \@q,
-                                "#$docid $pfx as expected ($xhc->{impl})";
-                }
+                like $rank, qr/\A\d+\z/, 'rank is a digit';
+                is scalar(@rest), 0, 'no extra rows returned';
         }
         my $nr;
         for my $i (7, 8, 39, 40) {
@@ -276,6 +268,20 @@ for my $n (@NO_CXX) {
         my @oids = (join('', @res) =~ /^([a-f0-9]{7}) /gms);
         is $nr_out, scalar(@oids), "output count matches $xhc->{impl}" or
                 diag explain(\@res, \@err);
+
+        if ($ENV{TEST_XH_TIMEOUT}) {
+                diag 'testing timeouts...';
+                for my $j (qw(0 1)) {
+                        my $t0 = now;
+                        $r = $xhc->mkreq(undef, qw(test_sleep -K 1 -d),
+                                        $ibx_idx[0]);
+                        is readline($r), undef, 'got EOF';
+                        my $diff = now - $t0;
+                        ok $diff < 3, "timeout didn't take too long -j$j";
+                        ok $diff >= 0.9, "timeout didn't fire prematurely -j$j";
+                        $xhc = PublicInbox::XapClient::start_helper('-j1');
+                }
+        }
 }
 
 done_testing;