]> Sergey Matveev's repositories - public-inbox.git/commitdiff
testcommon: DESTROY: wait for killed daemon
authorEric Wong <e@yhbt.net>
Sat, 11 Apr 2020 10:53:27 +0000 (10:53 +0000)
committerEric Wong <e@yhbt.net>
Wed, 15 Apr 2020 10:16:05 +0000 (10:16 +0000)
Otherwise, the waitpid(-1, 0) call in Xapcmd::process_queue()
may reap it in a subsequent test when using t/run.perl to reuse
processes for testing.

While we're at it, make Xapcmd::process_queue warn about unknown
PIDs in case other PIDs leak through to us in the future.

lib/PublicInbox/TestCommon.pm
lib/PublicInbox/Xapcmd.pm

index 6e3e9d8c8f506a92b195f15c4cd558a60b8ef31a..e9efbac71264fe47b36f87c5bb9252c26c36aff1 100644 (file)
@@ -319,8 +319,9 @@ sub kill {
 }
 
 sub join {
-       my ($self) = @_;
+       my ($self, $sig) = @_;
        my $pid = delete $self->{pid} or return;
+       CORE::kill($sig, $pid) if defined $sig;
        my $ret = waitpid($pid, 0);
        defined($ret) or die "waitpid($pid): $!";
        $ret == $pid or die "waitpid($pid) != $ret";
@@ -333,8 +334,7 @@ sub DESTROY {
                PublicInbox::TestCommon::wait_for_tail();
                CORE::kill('TERM', $tail);
        }
-       my $pid = delete $self->{pid} or return;
-       CORE::kill('TERM', $pid);
+       $self->join('TERM');
 }
 
 1;
index 8e2b9063c7443e3f0b8916560e22f054789dc71b..337978bd1a8799b79d10a315341333b06cf6ae3c 100644 (file)
@@ -142,7 +142,11 @@ sub process_queue {
                while (scalar keys %pids) {
                        my $pid = waitpid(-1, 0);
                        my $args = delete $pids{$pid};
-                       die join(' ', @$args)." failed: $?\n" if $?;
+                       if ($args) {
+                               die join(' ', @$args)." failed: $?\n" if $?;
+                       } else {
+                               warn "unknown PID($pid) reaped: $?\n";
+                       }
                }
        }
 }