- 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 (tick(0.01)) {
+ 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');
+ }