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};
15 our ($lei_opt, $lei_out, $lei_err, $lei_cwdfh);
17 @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
18 run_script start_script key2sub xsys xsys_e xqx eml_load tick
19 have_xapian_compact json_utf8 setup_public_inboxes create_inbox
20 tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
21 test_httpd xbail require_cmd);
23 my @methods = grep(!/\W/, @Test::More::EXPORT);
24 eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
26 push @EXPORT, @methods;
29 sub xbail (@) { BAIL_OUT join(' ', map { ref() ? (explain($_)) : ($_) } @_) }
33 open(my $fh, '<', $path) or die "open $path: $!";
34 require PublicInbox::Eml;
35 PublicInbox::Eml->new(\(do { local $/; <$fh> }));
41 unless (defined $base) {
42 ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
44 my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXX", TMPDIR => 1);
45 ($tmpdir->dirname, $tmpdir);
52 Type => Socket::SOCK_STREAM(),
57 die 'IPv4-only' if $ENV{TEST_IPV4_ONLY};
58 require IO::Socket::INET6;
59 IO::Socket::INET6->new(%opt, LocalAddr => '[::1]')
61 die 'IPv6-only' if $ENV{TEST_IPV6_ONLY};
62 IO::Socket::INET->new(%opt, LocalAddr => '127.0.0.1')
63 } || BAIL_OUT "failed to create TCP server: $! ($@)";
66 sub tcp_host_port ($) {
68 my ($h, $p) = ($s->sockhost, $s->sockport);
69 my $ipv4 = $s->sockdomain == Socket::AF_INET();
71 $ipv4 ? ($h, $p) : ("[$h]", $p);
73 $ipv4 ? "$h:$p" : "[$h]:$p";
78 my ($dest, %opt) = @_;
79 my $addr = tcp_host_port($dest);
80 my $s = ref($dest)->new(
82 Type => Socket::SOCK_STREAM(),
85 ) or BAIL_OUT "failed to connect to $addr: $!";
90 sub require_cmd ($;$) {
91 my ($cmd, $maybe) = @_;
92 require PublicInbox::Spawn;
93 my $bin = PublicInbox::Spawn::which($cmd);
95 $maybe ? 0 : plan(skip_all => "$cmd missing from PATH for $0");
98 sub have_xapian_compact () {
99 require_cmd($ENV{XAPIAN_COMPACT} || 'xapian-compact', 1);
102 sub require_git ($;$) {
103 my ($req, $maybe) = @_;
104 my ($req_maj, $req_min, $req_sub) = split(/\./, $req);
105 my ($cur_maj, $cur_min, $cur_sub) = (xqx([qw(git --version)])
106 =~ /version (\d+)\.(\d+)(?:\.(\d+))?/);
108 my $req_int = ($req_maj << 24) | ($req_min << 16) | ($req_sub // 0);
109 my $cur_int = ($cur_maj << 24) | ($cur_min << 16) | ($cur_sub // 0);
110 if ($cur_int < $req_int) {
113 "git $req+ required, have $cur_maj.$cur_min.$cur_sub";
120 my $maybe = pop @mods if $mods[-1] =~ /\A[0-9]+\z/;
122 while (my $mod = shift(@mods)) {
124 require_git(2.6, $maybe ? $maybe : ());
125 push @mods, qw(DBD::SQLite Search::Xapian);
126 $mod = 'json'; # fall-through
128 if ($mod eq 'json') {
129 $mod = 'Cpanel::JSON::XS||JSON::MaybeXS||JSON||JSON::PP'
130 } elsif ($mod eq '-httpd') {
131 push @mods, qw(Plack::Builder Plack::Util);
133 } elsif ($mod eq '-imapd') {
134 push @mods, qw(Parse::RecDescent DBD::SQLite
135 Email::Address::XS||Mail::Address);
137 } elsif ($mod eq '-nntpd') {
138 push @mods, qw(DBD::SQLite);
141 if ($mod eq 'Search::Xapian') {
142 if (eval { require PublicInbox::Search } &&
143 PublicInbox::Search::load_xapian()) {
146 } elsif (index($mod, '||') >= 0) { # "Foo||Bar"
148 for my $m (split(/\Q||\E/, $mod)) {
159 diag "require $mod: $@" if $mod =~ /Gcf2/;
161 } elsif ($mod eq 'IO::Socket::SSL' &&
162 # old versions of IO::Socket::SSL aren't supported
163 # by libnet, at least:
164 # https://rt.cpan.org/Ticket/Display.html?id=100529
165 !eval{ IO::Socket::SSL->VERSION(2.007); 1 }) {
170 my $m = join(', ', @need)." missing for $0";
171 skip($m, $maybe) if $maybe;
177 return $key if ($key eq 'git' || index($key, '/') >= 0);
178 # n.b. we may have scripts which don't start with "public-inbox" in
180 $key =~ s/\A([-\.])/public-inbox$1/;
184 my @io_mode = ([ *STDIN{IO}, '+<&' ], [ *STDOUT{IO}, '+>&' ],
185 [ *STDERR{IO}, '+>&' ]);
187 sub _prepare_redirects ($) {
190 for (my $fd = 0; $fd <= $#io_mode; $fd++) {
191 my $fh = $fhref->[$fd] or next;
192 my ($oldfh, $mode) = @{$io_mode[$fd]};
193 open my $orig, $mode, $oldfh or die "$oldfh $mode stash: $!";
194 $orig_io->[$fd] = $orig;
195 open $oldfh, $mode, $fh or die "$oldfh $mode redirect: $!";
200 sub _undo_redirects ($) {
202 for (my $fd = 0; $fd <= $#io_mode; $fd++) {
203 my $fh = $orig_io->[$fd] or next;
204 my ($oldfh, $mode) = @{$io_mode[$fd]};
205 open $oldfh, $mode, $fh or die "$$oldfh $mode redirect: $!";
209 # $opt->{run_mode} (or $ENV{TEST_RUN_MODE}) allows choosing between
210 # three ways to spawn our own short-lived Perl scripts for testing:
212 # 0 - (fork|vfork) + execve, the most realistic but slowest
213 # 1 - (not currently implemented)
214 # 2 - preloading and running in current process (slightly faster than 1)
216 # 2 is not compatible with scripts which use "exit" (which we'll try to
217 # avoid in the future).
219 our $run_script_exit_code;
220 sub RUN_SCRIPT_EXIT () { "RUN_SCRIPT_EXIT\n" };
221 sub run_script_exit {
222 $run_script_exit_code = $_[0] // 0;
229 $cached_scripts{$key} //= do {
230 my $f = key2script($key);
231 open my $fh, '<', $f or die "open $f: $!";
232 my $str = do { local $/; <$fh> };
233 my $pkg = (split(m!/!, $f))[-1];
234 $pkg =~ s/([a-z])([a-z0-9]+)(\.t)?\z/\U$1\E$2/;
237 $pkg = "PublicInbox::TestScript::$pkg";
243 *exit = \\&PublicInbox::TestCommon::run_script_exit;
245 # the below "line" directive is a magic comment, see perlsyn(1) manpage
257 my ($sub, $key, $argv) = @_;
258 local @ARGV = @$argv;
259 $run_script_exit_code = undef;
260 my $exit_code = eval { $sub->(@$argv) };
261 if ($@ eq RUN_SCRIPT_EXIT) {
263 $exit_code = $run_script_exit_code;
264 $? = ($exit_code << 8);
265 } elsif (defined($exit_code)) {
266 $? = ($exit_code << 8);
267 } elsif ($@) { # mimic die() behavior when uncaught
268 warn "E: eval-ed $key: $@\n";
269 $? = ($! << 8) if $!;
270 $? = (255 << 8) if $? == 0;
272 die "BUG: eval-ed $key: no exit code or \$@\n";
276 sub run_script ($;$$) {
277 my ($cmd, $env, $opt) = @_;
278 my ($key, @argv) = @$cmd;
279 my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 1;
280 my $sub = $run_mode == 0 ? undef : key2sub($key);
284 my $redir = $opt->{$fd};
285 my $ref = ref($redir);
286 if ($ref eq 'SCALAR') {
287 open my $fh, '+>', undef or die "open: $!";
289 $spawn_opt->{$fd} = $fh;
292 print $fh $$redir or die "print: $!";
293 seek($fh, 0, SEEK_SET) or die "seek: $!";
294 } elsif ($ref eq 'GLOB') {
295 $spawn_opt->{$fd} = $fhref->[$fd] = $redir;
297 die "unable to deal with $ref $redir";
300 if ($key =~ /-(index|convert|extindex|convert|xcpdb)\z/) {
301 unshift @argv, '--no-fsync';
303 if ($run_mode == 0) {
304 # spawn an independent new process, like real-world use cases:
305 require PublicInbox::Spawn;
306 my $cmd = [ key2script($key), @argv ];
307 if (my $d = $opt->{'-C'}) {
308 $cmd->[0] = File::Spec->rel2abs($cmd->[0]);
309 $spawn_opt->{'-C'} = $d;
311 my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
313 my $r = waitpid($pid, 0) // die "waitpid: $!";
314 $r == $pid or die "waitpid: expected $pid, got $r";
316 } else { # localize and run everything in the same process:
317 # note: "local *STDIN = *STDIN;" and so forth did not work in
318 # old versions of perl
319 local %ENV = $env ? (%ENV, %$env) : %ENV;
321 local $0 = join(' ', @$cmd);
322 my $orig_io = _prepare_redirects($fhref);
323 my $cwdfh = $lei_cwdfh;
324 if (my $d = $opt->{'-C'}) {
326 opendir $cwdfh, '.' or die "opendir .: $!";
328 chdir $d or die "chdir $d: $!";
330 _run_sub($sub, $key, \@argv);
331 eval { PublicInbox::Inbox::cleanup_task() };
332 die "fchdir(restore): $!" if $cwdfh && !chdir($cwdfh);
333 _undo_redirects($orig_io);
337 # slurp the redirects back into user-supplied strings
339 my $fh = $fhref->[$fd] or next;
341 seek($fh, 0, SEEK_SET) or die "seek: $!";
342 my $redir = $opt->{$fd};
350 my $tick = shift // 0.1;
351 select undef, undef, undef, $tick;
355 sub wait_for_tail ($;$) {
356 my ($tail_pid, $want) = @_;
358 if ($^O eq 'linux') { # GNU tail may use inotify
359 state $tail_has_inotify;
360 return tick if $want < 0 && $tail_has_inotify;
361 my $end = time + $wait;
365 readlink($_) =~ /\binotify\b/
366 } glob("/proc/$tail_pid/fd/*");
367 } while (!@ino && time <= $end and tick);
369 $tail_has_inotify = 1;
370 $ino[0] =~ s!/fd/!/fdinfo/!;
373 if (open my $fh, '<', $ino[0]) {
375 @info = grep(/^inotify wd:/, <$fh>);
377 } while (scalar(@info) < $want && time <= $end and tick);
383 # like system() built-in, but uses spawn() for env/rdr + vfork
385 my ($cmd, $env, $rdr) = @_;
393 run_script($cmd, $env, { %$rdr, run_mode => 0 });
397 sub xsys_e { # like "/bin/sh -e"
399 BAIL_OUT (ref $_[0] ? "@{$_[0]}" : "@_"). " failed \$?=$?"
402 # like `backtick` or qx{} op, but uses spawn() for env/rdr + vfork
404 my ($cmd, $env, $rdr) = @_;
406 run_script($cmd, $env, { %$rdr, run_mode => 0, 1 => \(my $out) });
407 wantarray ? split(/^/m, $out) : $out;
411 my ($cmd, $env, $opt) = @_;
412 my ($key, @argv) = @$cmd;
413 my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 2;
414 my $sub = $run_mode == 0 ? undef : key2sub($key);
416 if (my $tail_cmd = $ENV{TAIL}) {
419 next unless /\A--std(?:err|out)=(.+)\z/;
424 my $f = $opt->{$_} or next;
427 } elsif (ref($f) eq 'GLOB' && $^O eq 'linux') {
429 my $f = readlink "/proc/$$/fd/$fd";
430 push @paths, $f if -e $f;
435 $tail_pid = fork // die "fork: $!";
436 if ($tail_pid == 0) {
437 # make sure files exist, first
438 open my $fh, '>>', $_ for @paths;
439 open(STDOUT, '>&STDERR') or die "1>&2: $!";
440 exec(split(' ', $tail_cmd), @paths);
441 die "$tail_cmd failed: $!";
443 wait_for_tail($tail_pid, scalar @paths);
446 my $pid = fork // die "fork: $!\n";
448 eval { PublicInbox::DS->Reset };
449 # pretend to be systemd (cf. sd_listen_fds(3))
450 # 3 == SD_LISTEN_FDS_START
452 for ($fd = 0; 1; $fd++) {
454 last if $fd >= 3 && !defined($s);
456 my $fl = fcntl($s, F_GETFD, 0);
457 if (($fl & FD_CLOEXEC) != FD_CLOEXEC) {
458 warn "got FD:".fileno($s)." w/o CLOEXEC\n";
460 fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC);
461 dup2(fileno($s), $fd) or die "dup2 failed: $!\n";
463 %ENV = (%ENV, %$env) if $env;
466 $ENV{LISTEN_PID} = $$;
467 $ENV{LISTEN_FDS} = $fds;
469 $0 = join(' ', @$cmd);
471 eval { PublicInbox::DS->Reset };
472 _run_sub($sub, $key, \@argv);
473 POSIX::_exit($? >> 8);
475 exec(key2script($key), @argv);
476 die "FAIL: ",join(' ', $key, @argv), ": $!\n";
479 PublicInboxTestProcess->new($pid, $tail_pid);
482 # favor lei() or lei_ok() over $lei for new code
484 my ($cmd, $env, $xopt) = @_;
485 $lei_out = $lei_err = '';
487 ($env, $xopt) = grep { (!defined) || ref } @_;
488 $cmd = [ grep { defined && !ref } @_ ];
490 my $res = run_script(['lei', @$cmd], $env, $xopt // $lei_opt);
491 if ($lei_err ne '') {
492 if ($lei_err =~ /Use of uninitialized/ ||
493 $lei_err =~ m!\bArgument .*? isn't numeric in !) {
494 fail "lei_err=$lei_err";
496 diag "lei_err=$lei_err" if $lei_loud;
503 state $PWD = $ENV{PWD} // Cwd::getcwd();
504 my $msg = ref($_[-1]) eq 'SCALAR' ? pop(@_) : undef;
505 my $tmpdir = quotemeta(File::Spec->tmpdir);
506 # filter out anything that looks like a path name for consistent logs
507 my @msg = ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_;
510 s!\A([a-z0-9]+://)[^/]+/!$1\$HOST_PORT/!;
511 s!$tmpdir\b/(?:[^/]+/)?!\$TMPDIR/!g;
512 s!\Q$PWD\E\b!\$PWD!g;
515 ok(lei(@_), "lei @msg". ($msg ? " ($$msg)" : '')) or
516 diag "\$?=$? err=$lei_err";
520 state $x = ref(PublicInbox::Config->json)->new->utf8->canonical;
526 my $test_opt = shift // {};
528 opendir $lei_cwdfh, '.' or xbail "opendir .: $!";
529 require_git(2.6, 1) or skip('git 2.6+ required for lei test', 2);
530 my $mods = $test_opt->{mods} // [ 'lei' ];
531 require_mods(@$mods, 2);
532 require PublicInbox::Config;
535 delete $ENV{XDG_DATA_HOME};
536 delete $ENV{XDG_CONFIG_HOME};
537 $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
538 $ENV{GIT_COMMITTER_NAME} = 'lei user';
539 my (undef, $fn, $lineno) = caller(0);
540 my $t = "$fn:$lineno";
541 require PublicInbox::Spawn;
542 state $lei_daemon = PublicInbox::Spawn->can('send_cmd4') ||
543 eval { require Socket::MsgHdr; 1 };
544 unless ($lei_daemon) {
545 skip('Inline::C unconfigured/missing '.
546 '(mkdir -p ~/.cache/public-inbox/inline-c) OR Socket::MsgHdr missing',
549 $lei_opt = { 1 => \$lei_out, 2 => \$lei_err };
550 my ($daemon_pid, $for_destroy, $daemon_xrd);
551 my $tmpdir = $test_opt->{tmpdir};
552 File::Path::mkpath($tmpdir) if (defined $tmpdir && !-d $tmpdir);
553 ($tmpdir, $for_destroy) = tmpdir unless $tmpdir;
554 state $persist_xrd = $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
556 $ENV{TEST_LEI_ONESHOT} and
557 xbail 'TEST_LEI_ONESHOT no longer supported';
558 my $home = "$tmpdir/lei-daemon";
559 mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
560 local $ENV{HOME} = $home;
562 if ($persist_xrd && !$test_opt->{daemon_only}) {
563 $persist = $daemon_xrd = $persist_xrd;
565 $daemon_xrd = "$home/xdg_run";
566 mkdir($daemon_xrd, 0700) or BAIL_OUT "mkdir: $!";
568 local $ENV{XDG_RUNTIME_DIR} = $daemon_xrd;
570 if ($persist) { # remove before ~/.local gets removed
571 File::Path::rmtree([glob("$home/*")]);
572 File::Path::rmtree("$home/.config");
574 lei_ok(qw(daemon-pid), \"daemon-pid after $t");
575 chomp($daemon_pid = $lei_out);
577 fail("daemon not running after $t");
578 skip 'daemon died unexpectedly', 2;
580 ok(kill(0, $daemon_pid), "daemon running after $t");
581 lei_ok(qw(daemon-kill), \"daemon-kill after $t");
583 }; # SKIP for lei_daemon
586 kill(0, $daemon_pid) or last;
589 ok(!kill(0, $daemon_pid), "$t daemon stopped");
590 my $f = "$daemon_xrd/lei/errors.log";
591 open my $fh, '<', $f or BAIL_OUT "$f: $!";
594 "$t daemon XDG_RUNTIME_DIR/lei/errors.log empty");
596 }; # SKIP if missing git 2.6+ || Xapian || SQLite || json
599 # returns the pathname to a ~/.public-inbox/config in scalar context,
600 # ($test_home, $pi_config_pathname) in list context
601 sub setup_public_inboxes () {
602 my $test_home = "t/home2";
603 my $pi_config = "$test_home/.public-inbox/config";
604 my $stamp = "$test_home/setup-stamp";
605 my @ret = ($test_home, $pi_config);
606 return @ret if -f $stamp;
608 require PublicInbox::Lock;
609 my $lk = bless { lock_path => "$test_home/setup.lock" },
611 my $end = $lk->lock_for_scope;
612 return @ret if -f $stamp;
614 local $ENV{PI_CONFIG} = $pi_config;
616 run_script([qw(-init --skip-docdata), "-V$V",
617 '--newsgroup', "t.v$V", "t$V",
618 "$test_home/t$V", "http://example.com/t$V",
619 "t$V\@example.com" ]) or xbail "init v$V";
620 unlink "$test_home/t$V/description" or xbail "unlink $!";
622 require PublicInbox::Config;
623 require PublicInbox::InboxWritable;
624 my $cfg = PublicInbox::Config->new;
626 $cfg->each_inbox(sub {
628 $ibx->{-no_fsync} = 1;
629 my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
630 my $V = $ibx->version;
631 my @eml = (glob('t/*.eml'), 't/data/0001.patch');
633 next if $_ eq 't/psgi_v2-old.eml'; # dup mid
634 $im->add(eml_load($_)) or BAIL_OUT "v$V add $_";
639 $seen or BAIL_OUT 'no imports';
640 open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!";
644 sub create_inbox ($$;@) {
648 require PublicInbox::Lock;
649 require PublicInbox::InboxWritable;
650 my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
651 my $dir = "t/data-gen/$base.$ident";
654 mkdir $dir; # may race
655 -d $dir or BAIL_OUT "$dir could not be created: $!";
657 my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
658 $opt{inboxdir} = File::Spec->rel2abs($dir);
659 $opt{name} //= $ident;
660 my $scope = $lk->lock_for_scope;
661 my $pre_cb = delete $opt{pre_cb};
662 $pre_cb->($dir) if $pre_cb && $new;
664 my $no_gc = delete $opt{-no_gc};
665 my $tmpdir = delete $opt{tmpdir};
666 my $addr = $opt{address} // [];
667 $opt{-primary_address} //= $addr->[0] // "$ident\@example.com";
668 my $parallel = delete($opt{importer_parallel}) // 0;
669 my $creat_opt = { nproc => delete($opt{nproc}) // 1 };
670 my $ibx = PublicInbox::InboxWritable->new({ %opt }, $creat_opt);
671 if (!-f "$dir/creat.stamp") {
672 my $im = $ibx->importer($parallel);
676 my @to_gc = $ibx->version == 1 ? ($ibx->{inboxdir}) :
677 glob("$ibx->{inboxdir}/git/*.git");
678 for my $dir (@to_gc) {
679 xsys_e([ qw(git gc -q) ], { GIT_DIR => $dir });
682 open my $s, '>', "$dir/creat.stamp" or
683 BAIL_OUT "error creating $dir/creat.stamp: $!";
687 xsys([qw(/bin/cp -Rp), $dir, $tmpdir]) == 0 or
688 BAIL_OUT "cp $dir $tmpdir";
689 $opt{inboxdir} = $tmpdir;
690 $ibx = PublicInbox::InboxWritable->new(\%opt);
695 sub test_httpd ($$;$) {
696 my ($env, $client, $skip) = @_;
697 for (qw(PI_CONFIG TMPDIR)) {
698 $env->{$_} or BAIL_OUT "$_ unset";
701 require_mods(qw(Plack::Test::ExternalServer), $skip // 1);
702 my $sock = tcp_server() or die;
703 my ($out, $err) = map { "$env->{TMPDIR}/std$_.log" } qw(out err);
704 my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
705 my $td = start_script($cmd, $env, { 3 => $sock });
706 my ($h, $p) = tcp_host_port($sock);
707 local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
708 Plack::Test::ExternalServer::test_psgi(client => $client);
710 open my $fh, '<', $err or BAIL_OUT $!;
711 my $e = do { local $/; <$fh> };
712 if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
713 $e =~ s/^URL generation for redirects .*\n//gms;
715 is($e, '', 'no errors');
720 package PublicInboxTestProcess;
723 # prevent new threads from inheriting these objects
727 my ($klass, $pid, $tail_pid) = @_;
728 bless { pid => $pid, tail_pid => $tail_pid, owner => $$ }, $klass;
732 my ($self, $sig) = @_;
733 CORE::kill($sig // 'TERM', $self->{pid});
737 my ($self, $sig) = @_;
738 my $pid = delete $self->{pid} or return;
739 CORE::kill($sig, $pid) if defined $sig;
740 my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
741 $ret == $pid or die "waitpid($pid) != $ret";
746 return if $self->{owner} != $$;
747 if (my $tail_pid = delete $self->{tail_pid}) {
748 PublicInbox::TestCommon::wait_for_tail($tail_pid, -1);
749 CORE::kill('TERM', $tail_pid);
754 package PublicInbox::TestCommon::InboxWakeup;
756 sub on_inbox_unlock { ${$_[0]}->($_[1]) }