From d919b3441bdf61e8dfae0c08005b8a77662ddb91 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Sun, 20 Feb 2022 01:33:04 +0100 Subject: [PATCH] trace t/lei-sigpipe.t --- lib/PublicInbox/TestCommon.pm | 10 ++++++++++ t/lei-sigpipe.t | 22 +++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index ca732811..d8416f90 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -439,6 +439,9 @@ sub start_script { my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 2; my $sub = $run_mode == 0 ? undef : key2sub($key); my $tail; + open my $errfh, '+>>', "/build/start_script.log" or xbail $!; + $errfh->autoflush(1); + print $errfh "\nstart_script: begin\n"; if ($tail_cmd) { my @paths; for (@argv) { @@ -459,8 +462,10 @@ sub start_script { } $tail = tail_f(@paths); } + print $errfh "\nstart_script: fork\n"; my $pid = fork // die "fork: $!\n"; if ($pid == 0) { + print $errfh "\nstart_script: pid==0\n"; eval { PublicInbox::DS->Reset }; # pretend to be systemd (cf. sd_listen_fds(3)) # 3 == SD_LISTEN_FDS_START @@ -484,18 +489,23 @@ sub start_script { } if ($opt->{-C}) { chdir($opt->{-C}) or die "chdir: $!" } $0 = join(' ', @$cmd); + print $errfh "\nstart_script: pid==0: if sub\n"; if ($sub) { + print $errfh "\nstart_script: pid==0: sub\n"; eval { PublicInbox::DS->Reset }; _run_sub($sub, $key, \@argv); POSIX::_exit($? >> 8); } else { + print $errfh "\nstart_script: pid==0: exec $key\n"; exec(key2script($key), @argv); die "FAIL: ",join(' ', $key, @argv), ": $!\n"; } } + print $errfh "\nstart_script: pid!=0\n"; require PublicInbox::AutoReap; my $td = PublicInbox::AutoReap->new($pid); $td->{-extra} = $tail; + print $errfh "\nstart_script: pid!=0: tail\n"; $td; } diff --git a/t/lei-sigpipe.t b/t/lei-sigpipe.t index 6b2772a6..e5e701dd 100644 --- a/t/lei-sigpipe.t +++ b/t/lei-sigpipe.t @@ -6,7 +6,7 @@ use v5.10.1; use PublicInbox::TestCommon; use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE); test_lei(sub { - my $f = "$ENV{HOME}/big.eml"; + my $f = "/build/big.eml"; my $imported; for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) { pipe(my ($r, $w)) or BAIL_OUT $!; @@ -27,25 +27,33 @@ EOM } lei_ok(qw(import), $f) if $imported++ == 0; - open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!; + open my $errfh, '+>>', "/build/stderr.log" or xbail $!; + $errfh->autoflush(1); + print $errfh "\nlei-sigpipe: begin\n"; my $opt = { run_mode => 0, 2 => $errfh, 1 => $w }; my $cmd = [qw(lei q -q -t), @$out, 'z:1..']; my $tp = start_script($cmd, undef, $opt); + print $errfh "\nlei-sigpipe: start_script: done\n"; close $w; + print $errfh "\nlei-sigpipe: close w: done\n"; vec(my $rvec = '', fileno($r), 1) = 1; - if (!select($rvec, undef, undef, 30)) { + if (!select($rvec, undef, undef, 3)) { seek($errfh, 0, 0) or xbail $!; my $s = do { local $/; <$errfh> }; - xbail "lei q had no output after 30s, stderr=$s"; + xbail "lei q had no output after 3s, stderr=$s"; } + print $errfh "\nlei-sigpipe: sysread\n"; is(sysread($r, my $buf, 1), 1, 'read one byte'); + print $errfh "\nlei-sigpipe: sysread: done\n"; close $r; # trigger SIGPIPE + print $errfh "\nlei-sigpipe: close r: done\n"; $tp->join; + print $errfh "\nlei-sigpipe: join: done\n"; ok(WIFSIGNALED($?), "signaled @$out"); is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out"); - seek($errfh, 0, 0) or xbail $!; - my $s = do { local $/; <$errfh> }; - is($s, '', "quiet after sigpipe @$out"); + #seek($errfh, 0, 0) or xbail $!; + #my $s = do { local $/; <$errfh> }; + #is($s, '', "quiet after sigpipe @$out"); } }); -- 2.34.1