1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use_ok 'PublicInbox::Qspawn';
6 my $limiter = PublicInbox::Qspawn::Limiter->new(1);
8 my $x = PublicInbox::Qspawn->new([qw(true)]);
10 $x->start($limiter, sub {
12 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
13 ok(!$x->finish, 'no error on finish');
16 is($run, 1, 'callback ran alright');
20 my $x = PublicInbox::Qspawn->new([qw(false)]);
22 $x->start($limiter, sub {
24 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes from false');
26 is($err, 256, 'error on finish');
29 is($run, 1, 'callback ran alright');
32 foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
33 my $s = PublicInbox::Qspawn->new($cmd);
35 $s->start($limiter, sub {
38 is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
43 my $x = PublicInbox::Qspawn->new([qw(true)]);
44 $x->start($limiter, sub {
51 if ($cmd->[-1] =~ /false\z/) {
52 ok($s->finish, 'got error on false after sleep');
54 ok(!$s->finish, 'no error on sleep');
56 ok(!$_->[0]->finish, "true $_->[1] succeeded") foreach @t;
57 is_deeply([qw(sleep 0 1 2)], \@run, 'ran in order');