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) = @_;
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);
$nsent += $n;
fail "sent 0 bytes" if $n == 0;
}
- ok($!{EAGAIN}, "hit EAGAIN on send $desc");
+ ok($!{EAGAIN} || $!{ETOOMANYREFS},
+ "hit EAGAIN || ETOOMANYREFS on send $desc") or
+ diag "send failed with: $!";
ok($nsent > 0, 'sent some bytes');
socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
diag "sent $nr, retrying with more";
$nr += 2 * 1024 * 1024;
} else {
- ok($!{EMSGSIZE}, 'got EMSGSIZE');
- # diag "$nr bytes hits EMSGSIZE";
+ ok($!{EMSGSIZE} || $!{ENOBUFS},
+ 'got EMSGSIZE or ENOBUFS') or
+ diag "$nr bytes fails with: $!";
last;
}
}