From: Eric Wong Date: Thu, 25 Mar 2021 04:20:25 +0000 (+0200) Subject: t/cmd_ipc: workaround signal handling raciness X-Git-Tag: v1.7.0~904 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;ds=sidebyside;h=67379b592b29883618a380e81a3e2553702010f1;p=public-inbox.git t/cmd_ipc: workaround signal handling raciness 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). --- 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);