From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D34011FC0D for ; Thu, 25 Mar 2021 04:20:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/10] t/cmd_ipc: workaround signal handling raciness Date: Thu, 25 Mar 2021 06:20:25 +0200 Message-Id: <20210325042026.11270-10-e@80x24.org> In-Reply-To: <20210325042026.11270-1-e@80x24.org> References: <20210325042026.11270-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Perl can't check for interrupts when inside a blocking syscall, as there's no self-pipe mechanism inside Perl itself. So fork a child and have it repeated kill(2) instead of relying on alarm(3). --- t/cmd_ipc.t | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t index 84f8fb4d..c5e715a1 100644 --- a/t/cmd_ipc.t +++ b/t/cmd_ipc.t @@ -10,7 +10,7 @@ pipe(my ($r, $w)) or BAIL_OUT; my ($send, $recv); require_ok 'PublicInbox::Spawn'; my $SOCK_SEQPACKET = eval { Socket::SOCK_SEQPACKET() } // undef; -use Time::HiRes qw(alarm); +use Time::HiRes qw(usleep); my $do_test = sub { SKIP: { my ($type, $flag, $desc) = @_; @@ -53,13 +53,25 @@ my $do_test = sub { SKIP: { is_deeply(\@fds, [ undef ], "EAGAIN $desc"); $s2->blocking(1); - my $alrm = 0; - local $SIG{ALRM} = sub { $alrm++ }; - alarm(0.001); - @fds = $recv->($s2, $buf, length($src) + 1); - ok($!{EINTR}, "EINTR set by ($desc)"); - is_deeply(\@fds, [ undef ], "EINTR $desc"); - is($alrm, 1, 'SIGALRM hit'); + if ($ENV{TEST_ALRM}) { + my $alrm = 0; + local $SIG{ALRM} = sub { $alrm++ }; + my $tgt = $$; + my $pid = fork // xbail "fork: $!"; + if ($pid == 0) { + # need to loop since Perl signals are racy + # (the interpreter doesn't self-pipe) + while (usleep(1000)) { + kill 'ALRM', $tgt; + } + } + @fds = $recv->($s2, $buf, length($src) + 1); + ok($!{EINTR}, "EINTR set by ($desc)"); + kill('KILL', $pid); + waitpid($pid, 0); + is_deeply(\@fds, [ undef ], "EINTR $desc"); + ok($alrm, 'SIGALRM hit'); + } close $s1; @fds = $recv->($s2, $buf, length($src) + 1);