about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-10 12:15:01 +0000
committerEric Wong <e@80x24.org>2021-01-12 03:51:42 +0000
commita7e6a8cd68fb6d700337d8dbc7ee2c65ff3d2fc1 (patch)
tree5750ba57e3411ad3675e774c60bf8c2e77d0d672 /t
parentb90e8d6e02852c47d0c08198d8c7afb5dbe008d7 (diff)
downloadpublic-inbox-a7e6a8cd68fb6d700337d8dbc7ee2c65ff3d2fc1.tar.gz
Similar to git->cat_async, this will let us deal with responses
asynchronously, as well as being able to mix synchronous and
asynchronous code transparently (though perhaps not optimally).
Diffstat (limited to 't')
-rw-r--r--t/ipc.t25
1 files changed, 25 insertions, 0 deletions
diff --git a/t/ipc.t b/t/ipc.t
index 0efc5394..400fb768 100644
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -21,6 +21,7 @@ my $ipc = bless {}, 'PublicInbox::IPC';
 my @t = qw(array scalar scalarref undef);
 my $test = sub {
         my $x = shift;
+        my @res;
         for my $type (@t) {
                 my $m = "test_$type";
                 my @ret = $ipc->ipc_do($m);
@@ -29,10 +30,34 @@ my $test = sub {
 
                 $ipc->ipc_do($m);
 
+                $ipc->ipc_async($m, [], sub { push @res, \@_ }, \$m);
+
                 my $ret = $ipc->ipc_do($m);
                 my $exp = $ipc->$m;
                 is_deeply($ret, $exp, "!wantarray $m $x");
+
+                is_deeply(\@res, [ [ \$m, \@exp ] ], "async $m $x");
+                @res = ();
         }
+        $ipc->ipc_async_wait(-1);
+        is_deeply(\@res, [], 'no leftover results');
+        $ipc->ipc_async('test_die', ['die test'],
+                        sub { push @res, \@_  }, 'die arg');
+        $ipc->ipc_async_wait(1);
+        is(scalar(@res), 1, 'only one result');
+        is(scalar(@{$res[0]}), 2, 'result has 2-element array');
+        is($res[0]->[0], 'die arg', 'got async die arg '.$x);
+        is(ref($res[0]->[1]), 'PublicInbox::IPC::Die',
+                "exception type $x");
+        {
+                my $nr = PublicInbox::IPC::PIPE_BUF();
+                my $count = 0;
+                my $cb = sub { ++$count };
+                $ipc->ipc_async('test_undef', [], $cb) for (1..$nr);
+                $ipc->ipc_async_wait(-1);
+                is($count, $nr, "$x async runs w/o deadlock");
+        }
+
         my $ret = eval { $ipc->test_die('phail') };
         my $exp = $@;
         $ret = eval { $ipc->ipc_do('test_die', 'phail') };