diff options
Diffstat (limited to 't')
-rw-r--r-- | t/cindex.t | 2 | ||||
-rw-r--r-- | t/extsearch.t | 9 | ||||
-rw-r--r-- | t/imap_searchqp.t | 15 | ||||
-rw-r--r-- | t/psgi_v2.t | 54 | ||||
-rw-r--r-- | t/www_altid.t | 24 | ||||
-rw-r--r-- | t/xap_helper.t | 15 |
6 files changed, 104 insertions, 15 deletions
@@ -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(); 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 effe8bc5..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(); @@ -267,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; |