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($self->{rpipe}, my $buf, 1), 'read zero bytes');
28 ok(!finish_err($self), '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($self->{rpipe}, my $buf, 1),
40 'read zero bytes from false');
41 ok(finish_err($self), 'error on finish');
44 is($run, 1, 'callback ran alright');
47 foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
48 my $s = PublicInbox::Qspawn->new($cmd);
50 $s->start($limiter, sub {
53 is(0, sysread($self->{rpipe}, my $buf, 1), 'read zero bytes');
58 my $x = PublicInbox::Qspawn->new([qw(true)]);
59 $x->start($limiter, sub {
66 if ($cmd->[-1] =~ /false\z/) {
67 ok(finish_err($s), 'got error on false after sleep');
69 ok(!finish_err($s), 'no error on sleep');
71 ok(!finish_err($_->[0]), "true $_->[1] succeeded") foreach @t;
72 is_deeply([qw(sleep 0 1 2)], \@run, 'ran in order');