1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use_ok 'PublicInbox::Qspawn';
8 my $cmd = [qw(sh -c), 'echo >&2 err; echo out'];
9 my $qsp = PublicInbox::Qspawn->new($cmd, {}, { 2 => 1 });
11 $qsp->psgi_qx({}, undef, sub { $res = ${$_[0]} });
12 is($res, "err\nout\n", 'captured stderr and stdout');
21 my $limiter = PublicInbox::Qspawn::Limiter->new(1);
23 my $x = PublicInbox::Qspawn->new([qw(true)]);
25 $x->start($limiter, sub {
27 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
28 ok(!finish_err($x), 'no error on finish');
31 is($run, 1, 'callback ran alright');
35 my $x = PublicInbox::Qspawn->new([qw(false)]);
37 $x->start($limiter, sub {
39 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes from false');
40 ok(finish_err($x), 'error on finish');
43 is($run, 1, 'callback ran alright');
46 foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
47 my $s = PublicInbox::Qspawn->new($cmd);
49 $s->start($limiter, sub {
52 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
57 my $x = PublicInbox::Qspawn->new([qw(true)]);
58 $x->start($limiter, sub {
65 if ($cmd->[-1] =~ /false\z/) {
66 ok(finish_err($s), 'got error on false after sleep');
68 ok(!finish_err($s), 'no error on sleep');
70 ok(!finish_err($_->[0]), "true $_->[1] succeeded") foreach @t;
71 is_deeply([qw(sleep 0 1 2)], \@run, 'ran in order');