]> Sergey Matveev's repositories - public-inbox.git/blob - xt/lei-sigpipe.t
lei: test SIGPIPE, stop xsearch workers on client abort
[public-inbox.git] / xt / 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 Test::More;
7 use PublicInbox::TestCommon;
8 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
9 require_mods(qw(json DBD::SQLite Search::Xapian));
10 # XXX this needs an already configured lei instance with many messages
11
12 my $do_test = sub {
13         my $env = shift // {};
14         pipe(my ($r, $w)) or BAIL_OUT $!;
15         open my $err, '+>', undef or BAIL_OUT $!;
16         my $opt = { run_mode => 0, 1 => $w, 2 => $err };
17         my $tp = start_script([qw(lei q -t), 'bytes:1..'], $env, $opt);
18         close $w;
19         sysread($r, my $buf, 1);
20         close $r; # trigger SIGPIPE
21         $tp->join;
22         ok(WIFSIGNALED($?), 'signaled');
23         is(WTERMSIG($?), SIGPIPE, 'got SIGPIPE');
24         seek($err, 0, 0);
25         my @err = grep(!m{mkdir /dev/null\b}, <$err>);
26         is_deeply(\@err, [], 'no errors');
27 };
28
29 $do_test->();
30 $do_test->({XDG_RUNTIME_DIR => '/dev/null'});
31
32 done_testing;