about summary refs log tree commit homepage
path: root/t/qspawn.t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-24 03:41:53 +0000
committerEric Wong <e@80x24.org>2016-05-24 04:12:51 +0000
commit64aea34d06f71828b0bdd6ae177b9bcf22d752b4 (patch)
tree4f7df75d112aa4fe0b9056cf24688a2e42032019 /t/qspawn.t
parent8648f519a95872600689c3a5d6d87fd17770f9fc (diff)
downloadpublic-inbox-64aea34d06f71828b0bdd6ae177b9bcf22d752b4.tar.gz
Having an excessive amount of git-pack-objects processes is
dangerous to the health of the server.  Queue up process spawning
for long-running responses and serve them sequentially, instead.
Diffstat (limited to 't/qspawn.t')
-rw-r--r--t/qspawn.t60
1 files changed, 60 insertions, 0 deletions
diff --git a/t/qspawn.t b/t/qspawn.t
new file mode 100644
index 00000000..05072e24
--- /dev/null
+++ b/t/qspawn.t
@@ -0,0 +1,60 @@
+# Copyright (C) 2016 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 $x = PublicInbox::Qspawn->new([qw(true)]);
+        my $run = 0;
+        $x->start(sub {
+                my ($rpipe) = @_;
+                is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
+                ok(!$x->finish, 'no error on finish');
+                $run = 1;
+        });
+        is($run, 1, 'callback ran alright');
+}
+
+{
+        my $x = PublicInbox::Qspawn->new([qw(false)]);
+        my $run = 0;
+        $x->start(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');
+                $run = 1;
+        });
+        is($run, 1, 'callback ran alright');
+}
+
+foreach my $cmd ([qw(sleep 1)], [qw(sh -c), 'sleep 1; false']) {
+        my $s = PublicInbox::Qspawn->new($cmd);
+        my @run;
+        $s->start(sub {
+                my ($rpipe) = @_;
+                push @run, 'sleep';
+                is(0, sysread($rpipe, my $buf, 1), 'read zero bytes');
+        });
+        my $n = 0;
+        my @t = map {
+                my $i = $n++;
+                my $x = PublicInbox::Qspawn->new([qw(true)]);
+                $x->start(sub {
+                        my ($rpipe) = @_;
+                        push @run, $i;
+                });
+                [$x, $i]
+        } (0..2);
+
+        if ($cmd->[-1] =~ /false\z/) {
+                ok($s->finish, 'got error on false after sleep');
+        } else {
+                ok(!$s->finish, 'no error on sleep');
+        }
+        ok(!$_->[0]->finish, "true $_->[1] succeeded") foreach @t;
+        is_deeply([qw(sleep 0 1 2)], \@run, 'ran in order');
+}
+
+done_testing();
+
+1;