]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-sigpipe.t
t/lei-sigpipe: attempt to improve diagnostics for stuck test
[public-inbox.git] / t / lei-sigpipe.t
1 #!perl -w
2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::TestCommon;
7 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
8 test_lei(sub {
9         my $f = "$ENV{HOME}/big.eml";
10         my $imported;
11         for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
12                 pipe(my ($r, $w)) or BAIL_OUT $!;
13                 my $size = 65536;
14                 if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
15                         $size = 4096;
16                 }
17                 unless (-f $f) {
18                         open my $fh, '>', $f or xbail "open $f: $!";
19                         print $fh <<'EOM' or xbail;
20 From: big@example.com
21 Message-ID: <big@example.com>
22 EOM
23                         print $fh 'Subject:';
24                         print $fh (' '.('x' x 72)."\n") x (($size / 73) + 1);
25                         print $fh "\nbody\n";
26                         close $fh or xbail "close: $!";
27                 }
28
29                 lei_ok(qw(import), $f) if $imported++ == 0;
30                 open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!;
31                 my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
32                 my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
33                 my $tp = start_script($cmd, undef, $opt);
34                 close $w;
35                 vec(my $rvec = '', fileno($r), 1) = 1;
36                 if (!select($rvec, undef, undef, 30)) {
37                         seek($errfh, 0, 0) or xbail $!;
38                         my $s = do { local $/; <$errfh> };
39                         xbail "lei q had no output after 30s, stderr=$s";
40                 }
41                 is(sysread($r, my $buf, 1), 1, 'read one byte');
42                 close $r; # trigger SIGPIPE
43                 $tp->join;
44                 ok(WIFSIGNALED($?), "signaled @$out");
45                 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
46                 seek($errfh, 0, 0) or xbail $!;
47                 my $s = do { local $/; <$errfh> };
48                 is($s, '', "quiet after sigpipe @$out");
49         }
50 });
51
52 done_testing;