]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/qspawn.t
rename reference to git epochs as "partitions"
[public-inbox.git] / t / qspawn.t
index 05072e24d142bbfacd4d3d17725e17b927898a1e..ab6e37586fb14bc6ed57bc19da3f2c0474f9564c 100644 (file)
@@ -1,11 +1,21 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use Test::More;
 use_ok 'PublicInbox::Qspawn';
+
+{
+       my $cmd = [qw(sh -c), 'echo >&2 err; echo out'];
+       my $qsp = PublicInbox::Qspawn->new($cmd, {}, { 2 => 1 });
+       my $res;
+       $qsp->psgi_qx({}, undef, sub { $res = ${$_[0]} });
+       is($res, "err\nout\n", 'captured stderr and stdout');
+}
+
+my $limiter = PublicInbox::Qspawn::Limiter->new(1);
 {
        my $x = PublicInbox::Qspawn->new([qw(true)]);
        my $run = 0;
-       $x->start(sub {
+       $x->start($limiter, sub {
                my ($rpipe) = @_;
                is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
                ok(!$x->finish, 'no error on finish');
@@ -17,11 +27,11 @@ use_ok 'PublicInbox::Qspawn';
 {
        my $x = PublicInbox::Qspawn->new([qw(false)]);
        my $run = 0;
-       $x->start(sub {
+       $x->start($limiter, sub {
                my ($rpipe) = @_;
                is(0, sysread($rpipe, my $buf, 1), 'read zero bytes from false');
                my $err = $x->finish;
-               is($err, 256, 'error on finish');
+               ok($err, 'error on finish');
                $run = 1;
        });
        is($run, 1, 'callback ran alright');
@@ -30,7 +40,7 @@ use_ok 'PublicInbox::Qspawn';
 foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
        my $s = PublicInbox::Qspawn->new($cmd);
        my @run;
-       $s->start(sub {
+       $s->start($limiter, sub {
                my ($rpipe) = @_;
                push @run, 'sleep';
                is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
@@ -39,7 +49,7 @@ foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
        my @t = map {
                my $i = $n++;
                my $x = PublicInbox::Qspawn->new([qw(true)]);
-               $x->start(sub {
+               $x->start($limiter, sub {
                        my ($rpipe) = @_;
                        push @run, $i;
                });