about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-14 13:16:07 +0000
committerEric Wong <e@80x24.org>2021-10-15 02:23:26 +0000
commit4b5a1b5787edee2a3b6cc10a3ccc5721f1414268 (patch)
tree5439effe167100e8c2865a92ddc4df4b2bf6c0df /lib/PublicInbox/TestCommon.pm
parentf64fdbc7cc19a34f471abaeada9195597bf7a282 (diff)
downloadpublic-inbox-4b5a1b5787edee2a3b6cc10a3ccc5721f1414268.tar.gz
By relying more on pgroups for remaining remaining processes,
this lets us pause all curl+tail subprocesses with a single
kill(2) to avoid cluttering stderr.

We won't bother pausing the pigz/gzip/bzip2/xz compressor
process not cat-file processes, though, since those don't write
to the terminal and they idle soon after the workers react to
SIGSTOP.

AutoReap is hoisted out from TestCommon.pm.  CLONE_SKIP
is gone since we won't be using Perl threads any time
soon (they're discouraged by the maintainers of Perl).
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm36
1 files changed, 3 insertions, 33 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 57f1db95..83577999 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -6,6 +6,7 @@ package PublicInbox::TestCommon;
 use strict;
 use parent qw(Exporter);
 use v5.10.1;
+use PublicInbox::AutoReap;
 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
 use POSIX qw(dup2);
 use IO::Socket::INET;
@@ -429,7 +430,7 @@ sub tail_f (@) {
         require PublicInbox::Spawn;
         my $pid = PublicInbox::Spawn::spawn($cmd, undef, { 1 => 2 });
         wait_for_tail($pid, scalar @_);
-        PublicInboxTestProcess->new($pid, \&wait_for_tail);
+        PublicInbox::AutoReap->new($pid, \&wait_for_tail);
 }
 
 sub start_script {
@@ -492,7 +493,7 @@ sub start_script {
                         die "FAIL: ",join(' ', $key, @argv), ": $!\n";
                 }
         }
-        my $td = PublicInboxTestProcess->new($pid);
+        my $td = PublicInbox::AutoReap->new($pid);
         $td->{-extra} = $tail;
         $td;
 }
@@ -742,37 +743,6 @@ sub test_httpd ($$;$) {
 };
 
 
-package PublicInboxTestProcess;
-use strict;
-
-# prevent new threads from inheriting these objects
-sub CLONE_SKIP { 1 }
-
-sub new {
-        my ($cls, $pid, $cb) = @_;
-        bless { pid => $pid, cb => $cb, owner => $$ }, $cls;
-}
-
-sub kill {
-        my ($self, $sig) = @_;
-        CORE::kill($sig // 'TERM', $self->{pid});
-}
-
-sub join {
-        my ($self, $sig) = @_;
-        my $pid = delete $self->{pid} or return;
-        $self->{cb}->() if defined $self->{cb};
-        CORE::kill($sig, $pid) if defined $sig;
-        my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
-        $ret == $pid or die "waitpid($pid) != $ret";
-}
-
-sub DESTROY {
-        my ($self) = @_;
-        return if $self->{owner} != $$;
-        $self->join('TERM');
-}
-
 package PublicInbox::TestCommon::InboxWakeup;
 use strict;
 sub on_inbox_unlock { ${$_[0]}->($_[1]) }