1 # Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # internal APIs used only for tests
5 package PublicInbox::TestCommon;
7 use parent qw(Exporter);
9 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
14 my $lei_loud = $ENV{TEST_LEI_ERR_LOUD};
16 @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
17 run_script start_script key2sub xsys xsys_e xqx eml_load tick
18 have_xapian_compact json_utf8 setup_public_inboxes create_inbox
19 tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
22 my @methods = grep(!/\W/, @Test::More::EXPORT);
23 eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
25 push @EXPORT, @methods;
28 sub xbail (@) { BAIL_OUT join(' ', map { ref() ? (explain($_)) : ($_) } @_) }
32 open(my $fh, '<', $path) or die "open $path: $!";
33 require PublicInbox::Eml;
34 PublicInbox::Eml->new(\(do { local $/; <$fh> }));
40 unless (defined $base) {
41 ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
43 my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXX", TMPDIR => 1);
44 ($tmpdir->dirname, $tmpdir);
51 Type => Socket::SOCK_STREAM(),
56 die 'IPv4-only' if $ENV{TEST_IPV4_ONLY};
57 require IO::Socket::INET6;
58 IO::Socket::INET6->new(%opt, LocalAddr => '[::1]')
60 die 'IPv6-only' if $ENV{TEST_IPV6_ONLY};
61 IO::Socket::INET->new(%opt, LocalAddr => '127.0.0.1')
62 } || BAIL_OUT "failed to create TCP server: $! ($@)";
65 sub tcp_host_port ($) {
67 my ($h, $p) = ($s->sockhost, $s->sockport);
68 my $ipv4 = $s->sockdomain == Socket::AF_INET();
70 $ipv4 ? ($h, $p) : ("[$h]", $p);
72 $ipv4 ? "$h:$p" : "[$h]:$p";
77 my ($dest, %opt) = @_;
78 my $addr = tcp_host_port($dest);
79 my $s = ref($dest)->new(
81 Type => Socket::SOCK_STREAM(),
84 ) or BAIL_OUT "failed to connect to $addr: $!";
89 sub require_git ($;$) {
90 my ($req, $maybe) = @_;
91 my ($req_maj, $req_min, $req_sub) = split(/\./, $req);
92 my ($cur_maj, $cur_min, $cur_sub) = (xqx([qw(git --version)])
93 =~ /version (\d+)\.(\d+)(?:\.(\d+))?/);
95 my $req_int = ($req_maj << 24) | ($req_min << 16) | ($req_sub // 0);
96 my $cur_int = ($cur_maj << 24) | ($cur_min << 16) | ($cur_sub // 0);
97 if ($cur_int < $req_int) {
100 "git $req+ required, have $cur_maj.$cur_min.$cur_sub";
107 my $maybe = pop @mods if $mods[-1] =~ /\A[0-9]+\z/;
109 while (my $mod = shift(@mods)) {
111 require_git(2.6, $maybe ? $maybe : ());
112 push @mods, qw(DBD::SQLite Search::Xapian);
113 $mod = 'json'; # fall-through
115 if ($mod eq 'json') {
116 $mod = 'Cpanel::JSON::XS||JSON::MaybeXS||JSON||JSON::PP'
117 } elsif ($mod eq '-httpd') {
118 push @mods, qw(Plack::Builder Plack::Util);
120 } elsif ($mod eq '-imapd') {
121 push @mods, qw(Parse::RecDescent DBD::SQLite
122 Email::Address::XS||Mail::Address);
124 } elsif ($mod eq '-nntpd') {
125 push @mods, qw(DBD::SQLite);
128 if ($mod eq 'Search::Xapian') {
129 if (eval { require PublicInbox::Search } &&
130 PublicInbox::Search::load_xapian()) {
133 } elsif (index($mod, '||') >= 0) { # "Foo||Bar"
135 for my $m (split(/\Q||\E/, $mod)) {
147 } elsif ($mod eq 'IO::Socket::SSL' &&
148 # old versions of IO::Socket::SSL aren't supported
149 # by libnet, at least:
150 # https://rt.cpan.org/Ticket/Display.html?id=100529
151 !eval{ IO::Socket::SSL->VERSION(2.007); 1 }) {
156 my $m = join(', ', @need)." missing for $0";
157 skip($m, $maybe) if $maybe;
163 return $key if ($key eq 'git' || index($key, '/') >= 0);
164 # n.b. we may have scripts which don't start with "public-inbox" in
166 $key =~ s/\A([-\.])/public-inbox$1/;
170 my @io_mode = ([ *STDIN{IO}, '+<&' ], [ *STDOUT{IO}, '+>&' ],
171 [ *STDERR{IO}, '+>&' ]);
173 sub _prepare_redirects ($) {
176 for (my $fd = 0; $fd <= $#io_mode; $fd++) {
177 my $fh = $fhref->[$fd] or next;
178 my ($oldfh, $mode) = @{$io_mode[$fd]};
179 open my $orig, $mode, $oldfh or die "$oldfh $mode stash: $!";
180 $orig_io->[$fd] = $orig;
181 open $oldfh, $mode, $fh or die "$oldfh $mode redirect: $!";
186 sub _undo_redirects ($) {
188 for (my $fd = 0; $fd <= $#io_mode; $fd++) {
189 my $fh = $orig_io->[$fd] or next;
190 my ($oldfh, $mode) = @{$io_mode[$fd]};
191 open $oldfh, $mode, $fh or die "$$oldfh $mode redirect: $!";
195 # $opt->{run_mode} (or $ENV{TEST_RUN_MODE}) allows choosing between
196 # three ways to spawn our own short-lived Perl scripts for testing:
198 # 0 - (fork|vfork) + execve, the most realistic but slowest
199 # 1 - (not currently implemented)
200 # 2 - preloading and running in current process (slightly faster than 1)
202 # 2 is not compatible with scripts which use "exit" (which we'll try to
203 # avoid in the future).
205 our $run_script_exit_code;
206 sub RUN_SCRIPT_EXIT () { "RUN_SCRIPT_EXIT\n" };
207 sub run_script_exit {
208 $run_script_exit_code = $_[0] // 0;
215 $cached_scripts{$key} //= do {
216 my $f = key2script($key);
217 open my $fh, '<', $f or die "open $f: $!";
218 my $str = do { local $/; <$fh> };
219 my $pkg = (split(m!/!, $f))[-1];
220 $pkg =~ s/([a-z])([a-z0-9]+)(\.t)?\z/\U$1\E$2/;
223 $pkg = "PublicInbox::TestScript::$pkg";
229 *exit = \\&PublicInbox::TestCommon::run_script_exit;
231 # the below "line" directive is a magic comment, see perlsyn(1) manpage
243 my ($sub, $key, $argv) = @_;
244 local @ARGV = @$argv;
245 $run_script_exit_code = undef;
246 my $exit_code = eval { $sub->(@$argv) };
247 if ($@ eq RUN_SCRIPT_EXIT) {
249 $exit_code = $run_script_exit_code;
250 $? = ($exit_code << 8);
251 } elsif (defined($exit_code)) {
252 $? = ($exit_code << 8);
253 } elsif ($@) { # mimic die() behavior when uncaught
254 warn "E: eval-ed $key: $@\n";
255 $? = ($! << 8) if $!;
256 $? = (255 << 8) if $? == 0;
258 die "BUG: eval-ed $key: no exit code or \$@\n";
262 sub run_script ($;$$) {
263 my ($cmd, $env, $opt) = @_;
264 my ($key, @argv) = @$cmd;
265 my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 1;
266 my $sub = $run_mode == 0 ? undef : key2sub($key);
270 my $redir = $opt->{$fd};
271 my $ref = ref($redir);
272 if ($ref eq 'SCALAR') {
273 open my $fh, '+>', undef or die "open: $!";
275 $spawn_opt->{$fd} = $fh;
278 print $fh $$redir or die "print: $!";
279 seek($fh, 0, SEEK_SET) or die "seek: $!";
280 } elsif ($ref eq 'GLOB') {
281 $spawn_opt->{$fd} = $fhref->[$fd] = $redir;
283 die "unable to deal with $ref $redir";
286 if ($key =~ /-(index|convert|extindex|convert|xcpdb)\z/) {
287 unshift @argv, '--no-fsync';
289 if ($run_mode == 0) {
290 # spawn an independent new process, like real-world use cases:
291 require PublicInbox::Spawn;
292 my $cmd = [ key2script($key), @argv ];
293 if (my $d = $opt->{'-C'}) {
294 $cmd->[0] = File::Spec->rel2abs($cmd->[0]);
295 $spawn_opt->{'-C'} = $d;
297 my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
299 my $r = waitpid($pid, 0) // die "waitpid: $!";
300 $r == $pid or die "waitpid: expected $pid, got $r";
302 } else { # localize and run everything in the same process:
303 # note: "local *STDIN = *STDIN;" and so forth did not work in
304 # old versions of perl
305 local %ENV = $env ? (%ENV, %$env) : %ENV;
307 local $0 = join(' ', @$cmd);
308 my $orig_io = _prepare_redirects($fhref);
310 if (my $d = $opt->{'-C'}) {
311 opendir $cwdfh, '.' or die "opendir .: $!";
312 chdir $d or die "chdir $d: $!";
314 _run_sub($sub, $key, \@argv);
315 eval { PublicInbox::Inbox::cleanup_task() };
316 die "chdir(restore): $!" if $cwdfh && !chdir($cwdfh);
317 _undo_redirects($orig_io);
321 # slurp the redirects back into user-supplied strings
323 my $fh = $fhref->[$fd] or next;
324 seek($fh, 0, SEEK_SET) or die "seek: $!";
325 my $redir = $opt->{$fd};
333 my $tick = shift // 0.1;
334 select undef, undef, undef, $tick;
338 sub wait_for_tail ($;$) {
339 my ($tail_pid, $want) = @_;
341 if ($^O eq 'linux') { # GNU tail may use inotify
342 state $tail_has_inotify;
343 return tick if $want < 0 && $tail_has_inotify;
344 my $end = time + $wait;
348 readlink($_) =~ /\binotify\b/
349 } glob("/proc/$tail_pid/fd/*");
350 } while (!@ino && time <= $end and tick);
352 $tail_has_inotify = 1;
353 $ino[0] =~ s!/fd/!/fdinfo/!;
356 if (open my $fh, '<', $ino[0]) {
358 @info = grep(/^inotify wd:/, <$fh>);
360 } while (scalar(@info) < $want && time <= $end and tick);
366 # like system() built-in, but uses spawn() for env/rdr + vfork
368 my ($cmd, $env, $rdr) = @_;
376 run_script($cmd, $env, { %$rdr, run_mode => 0 });
380 sub xsys_e { # like "/bin/sh -e"
382 BAIL_OUT (ref $_[0] ? "@{$_[0]}" : "@_"). " failed \$?=$?"
385 # like `backtick` or qx{} op, but uses spawn() for env/rdr + vfork
387 my ($cmd, $env, $rdr) = @_;
389 run_script($cmd, $env, { %$rdr, run_mode => 0, 1 => \(my $out) });
390 wantarray ? split(/^/m, $out) : $out;
394 my ($cmd, $env, $opt) = @_;
395 my ($key, @argv) = @$cmd;
396 my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 2;
397 my $sub = $run_mode == 0 ? undef : key2sub($key);
399 if (my $tail_cmd = $ENV{TAIL}) {
402 next unless /\A--std(?:err|out)=(.+)\z/;
407 my $f = $opt->{$_} or next;
410 } elsif (ref($f) eq 'GLOB' && $^O eq 'linux') {
412 my $f = readlink "/proc/$$/fd/$fd";
413 push @paths, $f if -e $f;
418 $tail_pid = fork // die "fork: $!";
419 if ($tail_pid == 0) {
420 # make sure files exist, first
421 open my $fh, '>>', $_ for @paths;
422 open(STDOUT, '>&STDERR') or die "1>&2: $!";
423 exec(split(' ', $tail_cmd), @paths);
424 die "$tail_cmd failed: $!";
426 wait_for_tail($tail_pid, scalar @paths);
429 my $pid = fork // die "fork: $!\n";
431 eval { PublicInbox::DS->Reset };
432 # pretend to be systemd (cf. sd_listen_fds(3))
433 # 3 == SD_LISTEN_FDS_START
435 for ($fd = 0; 1; $fd++) {
437 last if $fd >= 3 && !defined($s);
439 my $fl = fcntl($s, F_GETFD, 0);
440 if (($fl & FD_CLOEXEC) != FD_CLOEXEC) {
441 warn "got FD:".fileno($s)." w/o CLOEXEC\n";
443 fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC);
444 dup2(fileno($s), $fd) or die "dup2 failed: $!\n";
446 %ENV = (%ENV, %$env) if $env;
449 $ENV{LISTEN_PID} = $$;
450 $ENV{LISTEN_FDS} = $fds;
452 $0 = join(' ', @$cmd);
454 eval { PublicInbox::DS->Reset };
455 _run_sub($sub, $key, \@argv);
456 POSIX::_exit($? >> 8);
458 exec(key2script($key), @argv);
459 die "FAIL: ",join(' ', $key, @argv), ": $!\n";
462 PublicInboxTestProcess->new($pid, $tail_pid);
465 sub have_xapian_compact () {
466 require PublicInbox::Spawn;
467 # $ENV{XAPIAN_COMPACT} is used by PublicInbox/Xapcmd.pm, too
468 PublicInbox::Spawn::which($ENV{XAPIAN_COMPACT} || 'xapian-compact');
471 our ($err_skip, $lei_opt, $lei_out, $lei_err);
472 # favor lei() or lei_ok() over $lei for new code
474 my ($cmd, $env, $xopt) = @_;
475 $lei_out = $lei_err = '';
477 ($env, $xopt) = grep { (!defined) || ref } @_;
478 $cmd = [ grep { defined && !ref } @_ ];
480 my $res = run_script(['lei', @$cmd], $env, $xopt // $lei_opt);
482 $lei_err = join('', grep(!/$err_skip/, split(/^/m, $lei_err)));
483 if ($lei_err ne '') {
484 if ($lei_err =~ /Use of uninitialized/ ||
485 $lei_err =~ m!\bArgument .*? isn't numeric in !) {
486 fail "lei_err=$lei_err";
488 diag "lei_err=$lei_err" if $lei_loud;
495 state $PWD = $ENV{PWD} // Cwd::getcwd();
496 my $msg = ref($_[-1]) eq 'SCALAR' ? pop(@_) : undef;
497 my $tmpdir = quotemeta(File::Spec->tmpdir);
498 # filter out anything that looks like a path name for consistent logs
499 my @msg = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
502 s!\A([a-z0-9]+://)[^/]+/!$1\$HOST_PORT/!;
503 s!$tmpdir\b/(?:[^/]+/)?!\$TMPDIR/!g;
504 s!\Q$PWD\E\b!\$PWD!g;
507 ok(lei(@_), "lei @msg". ($msg ? " ($$msg)" : '')) or
508 diag "\$?=$? err=$lei_err";
512 state $x = ref(PublicInbox::Config->json)->new->utf8->canonical;
518 my $test_opt = shift // {};
519 require_git(2.6, 1) or skip('git 2.6+ required for lei test', 2);
520 require_mods(qw(json DBD::SQLite Search::Xapian), 2);
521 require PublicInbox::Config;
523 delete $ENV{XDG_DATA_HOME};
524 delete $ENV{XDG_CONFIG_HOME};
525 $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
526 $ENV{GIT_COMMITTER_NAME} = 'lei user';
527 my (undef, $fn, $lineno) = caller(0);
528 my $t = "$fn:$lineno";
529 require PublicInbox::Spawn;
530 state $lei_daemon = PublicInbox::Spawn->can('send_cmd4') ||
531 eval { require Socket::MsgHdr; 1 };
532 # XXX fix and move this inside daemon-only before 1.7 release
533 skip <<'EOM', 1 unless $lei_daemon;
534 Socket::MsgHdr missing or Inline::C is unconfigured/missing
536 $lei_opt = { 1 => \$lei_out, 2 => \$lei_err };
537 my ($daemon_pid, $for_destroy, $daemon_xrd);
538 my $tmpdir = $test_opt->{tmpdir};
539 ($tmpdir, $for_destroy) = tmpdir unless $tmpdir;
540 state $persist_xrd = $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
542 skip 'TEST_LEI_ONESHOT set', 1 if $ENV{TEST_LEI_ONESHOT};
543 my $home = "$tmpdir/lei-daemon";
544 mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
545 local $ENV{HOME} = $home;
547 if ($persist_xrd && !$test_opt->{daemon_only}) {
548 $persist = $daemon_xrd = $persist_xrd;
550 $daemon_xrd = "$home/xdg_run";
551 mkdir($daemon_xrd, 0700) or BAIL_OUT "mkdir: $!";
553 local $ENV{XDG_RUNTIME_DIR} = $daemon_xrd;
556 lei_ok(qw(daemon-pid), \"daemon-pid after $t");
557 chomp($daemon_pid = $lei_out);
559 fail("daemon not running after $t");
560 skip 'daemon died unexpectedly', 2;
562 ok(kill(0, $daemon_pid), "daemon running after $t");
563 lei_ok(qw(daemon-kill), \"daemon-kill after $t");
565 }; # SKIP for lei_daemon
566 unless ($test_opt->{daemon_only}) {
567 $ENV{TEST_LEI_DAEMON_ONLY} and
568 skip 'TEST_LEI_DAEMON_ONLY set', 1;
569 require_ok 'PublicInbox::LEI';
570 my $home = "$tmpdir/lei-oneshot";
571 mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
572 local $ENV{HOME} = $home;
573 # force sun_path[108] overflow:
574 my $xrd = "$home/1shot-test".('.sun_path' x 108);
575 local $err_skip = qr!\Q$xrd!; # for lei() filtering
576 local $ENV{XDG_RUNTIME_DIR} = $xrd;
581 kill(0, $daemon_pid) or last;
584 ok(!kill(0, $daemon_pid), "$t daemon stopped after oneshot");
585 my $f = "$daemon_xrd/lei/errors.log";
586 open my $fh, '<', $f or BAIL_OUT "$f: $!";
589 "$t daemon XDG_RUNTIME_DIR/lei/errors.log empty");
591 }; # SKIP if missing git 2.6+ || Xapian || SQLite || json
594 # returns the pathname to a ~/.public-inbox/config in scalar context,
595 # ($test_home, $pi_config_pathname) in list context
596 sub setup_public_inboxes () {
597 my $test_home = "t/home2";
598 my $pi_config = "$test_home/.public-inbox/config";
599 my $stamp = "$test_home/setup-stamp";
600 my @ret = ($test_home, $pi_config);
601 return @ret if -f $stamp;
603 require PublicInbox::Lock;
604 my $lk = bless { lock_path => "$test_home/setup.lock" },
606 my $end = $lk->lock_for_scope;
607 return @ret if -f $stamp;
609 local $ENV{PI_CONFIG} = $pi_config;
611 run_script([qw(-init --skip-docdata), "-V$V",
612 '--newsgroup', "t.v$V", "t$V",
613 "$test_home/t$V", "http://example.com/t$V",
614 "t$V\@example.com" ]) or BAIL_OUT "init v$V";
616 require PublicInbox::Config;
617 require PublicInbox::InboxWritable;
618 my $cfg = PublicInbox::Config->new;
620 $cfg->each_inbox(sub {
622 $ibx->{-no_fsync} = 1;
623 my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
624 my $V = $ibx->version;
625 my @eml = (glob('t/*.eml'), 't/data/0001.patch');
627 next if $_ eq 't/psgi_v2-old.eml'; # dup mid
628 $im->add(eml_load($_)) or BAIL_OUT "v$V add $_";
633 $seen or BAIL_OUT 'no imports';
634 open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!";
638 sub create_inbox ($$;@) {
642 require PublicInbox::Lock;
643 require PublicInbox::InboxWritable;
644 my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
645 my $dir = "t/data-gen/$base.$ident";
648 mkdir $dir; # may race
649 -d $dir or BAIL_OUT "$dir could not be created: $!";
651 my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
652 $opt{inboxdir} = File::Spec->rel2abs($dir);
653 $opt{name} //= $ident;
654 my $scope = $lk->lock_for_scope;
655 my $pre_cb = delete $opt{pre_cb};
656 $pre_cb->($dir) if $pre_cb && $new;
658 my $no_gc = delete $opt{-no_gc};
659 my $tmpdir = delete $opt{tmpdir};
660 my $addr = $opt{address} // [];
661 $opt{-primary_address} //= $addr->[0] // "$ident\@example.com";
662 my $parallel = delete($opt{importer_parallel}) // 0;
663 my $creat_opt = { nproc => delete($opt{nproc}) // 1 };
664 my $ibx = PublicInbox::InboxWritable->new({ %opt }, $creat_opt);
665 if (!-f "$dir/creat.stamp") {
666 my $im = $ibx->importer($parallel);
670 my @to_gc = $ibx->version == 1 ? ($ibx->{inboxdir}) :
671 glob("$ibx->{inboxdir}/git/*.git");
672 for my $dir (@to_gc) {
673 xsys_e([ qw(git gc -q) ], { GIT_DIR => $dir });
676 open my $s, '>', "$dir/creat.stamp" or
677 BAIL_OUT "error creating $dir/creat.stamp: $!";
681 xsys([qw(/bin/cp -Rp), $dir, $tmpdir]) == 0 or
682 BAIL_OUT "cp $dir $tmpdir";
683 $opt{inboxdir} = $tmpdir;
684 $ibx = PublicInbox::InboxWritable->new(\%opt);
689 sub test_httpd ($$;$) {
690 my ($env, $client, $skip) = @_;
691 for (qw(PI_CONFIG TMPDIR)) {
692 $env->{$_} or BAIL_OUT "$_ unset";
695 require_mods(qw(Plack::Test::ExternalServer), $skip // 1);
696 my $sock = tcp_server() or die;
697 my ($out, $err) = map { "$env->{TMPDIR}/std$_.log" } qw(out err);
698 my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
699 my $td = start_script($cmd, $env, { 3 => $sock });
700 my ($h, $p) = tcp_host_port($sock);
701 local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
702 Plack::Test::ExternalServer::test_psgi(client => $client);
704 open my $fh, '<', $err or BAIL_OUT $!;
705 my $e = do { local $/; <$fh> };
706 if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
707 $e =~ s/^URL generation for redirects .*\n//gms;
709 is($e, '', 'no errors');
714 package PublicInboxTestProcess;
717 # prevent new threads from inheriting these objects
721 my ($klass, $pid, $tail_pid) = @_;
722 bless { pid => $pid, tail_pid => $tail_pid, owner => $$ }, $klass;
726 my ($self, $sig) = @_;
727 CORE::kill($sig // 'TERM', $self->{pid});
731 my ($self, $sig) = @_;
732 my $pid = delete $self->{pid} or return;
733 CORE::kill($sig, $pid) if defined $sig;
734 my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
735 $ret == $pid or die "waitpid($pid) != $ret";
740 return if $self->{owner} != $$;
741 if (my $tail_pid = delete $self->{tail_pid}) {
742 PublicInbox::TestCommon::wait_for_tail($tail_pid, -1);
743 CORE::kill('TERM', $tail_pid);
748 package PublicInbox::TestCommon::InboxWakeup;
750 sub on_inbox_unlock { ${$_[0]}->($_[1]) }