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:18 +0000
committerEric Wong <e@80x24.org>2021-01-12 03:51:43 +0000
commit3019046b3ab9736922762df111d60ef7647e36a3 (patch)
tree6cc7ec956a0c4e3b392367fa7bced25943dbc7b7 /t
parent7b79c918a5ea79f6adc380ca917b0353475ab29c (diff)
downloadpublic-inbox-3019046b3ab9736922762df111d60ef7647e36a3.tar.gz
It's easier to make the code more generic by transferring
all four FDs (std(in|out|err) + socket) instead of omitting
stdin.

We'll be reading from stdin on some imports, and possibly
outputting to stdout, so omitting stdin now would needlessly
complicate things.

The differences with IO::FDPass "1" code paths and the "4"
code paths used by Inline::C and Socket::MsgHdr are far too
much to support and test at the moment.
Diffstat (limited to 't')
-rw-r--r--t/cmd_ipc.t9
-rw-r--r--t/ipc.t53
-rw-r--r--t/lei.t6
3 files changed, 30 insertions, 38 deletions
diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t
index 22f73c19..0a0a4e00 100644
--- a/t/cmd_ipc.t
+++ b/t/cmd_ipc.t
@@ -79,13 +79,4 @@ SKIP: {
         }
 }
 
-SKIP: {
-        require_mods('IO::FDPass', 13);
-        require_ok 'PublicInbox::CmdIPC1';
-        $send = PublicInbox::CmdIPC1->can('send_cmd1');
-        $recv = PublicInbox::CmdIPC1->can('recv_cmd1');
-        $do_test->(SOCK_STREAM, 0, 'IO::FDPass stream');
-        $do_test->($SOCK_SEQPACKET, MSG_EOR, 'IO::FDPass seqpacket');
-}
-
 done_testing;
diff --git a/t/ipc.t b/t/ipc.t
index fd290809..22423a78 100644
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -6,6 +6,7 @@ use v5.10.1;
 use Test::More;
 use PublicInbox::TestCommon;
 use Fcntl qw(SEEK_SET);
+require_mods(qw(Storable||Sereal));
 require_ok 'PublicInbox::IPC';
 state $once = eval <<'';
 package PublicInbox::IPC;
@@ -94,8 +95,7 @@ my $test = sub {
 };
 $test->('local');
 
-SKIP: {
-        require_mods(qw(Storable||Sereal), 16);
+{
         my $pid = $ipc->ipc_worker_spawn('test worker');
         ok($pid > 0 && kill(0, $pid), 'worker spawned and running');
         defined($pid) or BAIL_OUT 'no spawn, no test';
@@ -112,7 +112,7 @@ SKIP: {
 $ipc->ipc_worker_stop; # idempotent
 
 # work queues
-$ipc->{wq_open_modes} = [qw( >&= >&= >&= )];
+$ipc->wq_set_recv_modes(qw( >&= >&= >&= ));
 pipe(my ($ra, $wa)) or BAIL_OUT $!;
 pipe(my ($rb, $wb)) or BAIL_OUT $!;
 pipe(my ($rc, $wc)) or BAIL_OUT $!;
@@ -136,7 +136,7 @@ for my $t ('local', 'worker', 'worker again') {
 
 # wq_do works across fork (siblings can feed)
 SKIP: {
-        skip 'Socket::MsgHdr, IO::FDPass, Inline::C missing', 7 if !$ppids[0];
+        skip 'Socket::MsgHdr or Inline::C missing', 3 if !$ppids[0];
         is_deeply(\@ppids, [$$, undef, undef],
                 'parent pid returned in wq_workers_start');
         my $pid = fork // BAIL_OUT $!;
@@ -161,28 +161,31 @@ SKIP: {
 }
 
 $ipc->wq_close;
-seek($warn, 0, SEEK_SET) or BAIL_OUT;
-my @warn = <$warn>;
-is(scalar(@warn), 3, 'warned 3 times');
-like($warn[0], qr/ wq_do: /, '1st warned from wq_do');
-like($warn[1], qr/ wq_worker: /, '2nd warned from wq_worker');
-is($warn[2], $warn[1], 'worker did not die');
-
-$SIG{__WARN__} = 'DEFAULT';
-is($ipc->wq_workers_start('wq', 1), $$, 'workers started again');
-is($ipc->wq_workers, 1, '1 worker started');
 SKIP: {
-        $ipc->WQ_MAX_WORKERS > 1 or
-                skip 'Inline::C or Socket::MsgHdr not available', 4;
-        $ipc->wq_worker_incr;
-        is($ipc->wq_workers, 2, 'worker count bumped');
-        $ipc->wq_worker_decr;
-        $ipc->wq_worker_decr_wait(10);
-        is($ipc->wq_workers, 1, 'worker count lowered');
-        is($ipc->wq_workers(2), 2, 'worker count set');
-        is($ipc->wq_workers, 2, 'worker count stayed set');
+        skip 'Socket::MsgHdr or Inline::C missing', 11 if !$ppids[0];
+        seek($warn, 0, SEEK_SET) or BAIL_OUT;
+        my @warn = <$warn>;
+        is(scalar(@warn), 3, 'warned 3 times');
+        like($warn[0], qr/ wq_do: /, '1st warned from wq_do');
+        like($warn[1], qr/ wq_worker: /, '2nd warned from wq_worker');
+        is($warn[2], $warn[1], 'worker did not die');
+
+        $SIG{__WARN__} = 'DEFAULT';
+        is($ipc->wq_workers_start('wq', 1), $$, 'workers started again');
+        is($ipc->wq_workers, 1, '1 worker started');
+        SKIP: {
+                $ipc->WQ_MAX_WORKERS > 1 or
+                        skip 'Inline::C or Socket::MsgHdr not available', 4;
+                $ipc->wq_worker_incr;
+                is($ipc->wq_workers, 2, 'worker count bumped');
+                $ipc->wq_worker_decr;
+                $ipc->wq_worker_decr_wait(10);
+                is($ipc->wq_workers, 1, 'worker count lowered');
+                is($ipc->wq_workers(2), 2, 'worker count set');
+                is($ipc->wq_workers, 2, 'worker count stayed set');
+        }
+        $ipc->wq_close;
+        is($ipc->wq_workers, undef, 'workers undef after close');
 }
-$ipc->wq_close;
-is($ipc->wq_workers, undef, 'workers undef after close');
 
 done_testing;
diff --git a/t/lei.t b/t/lei.t
index 992800a5..6819f182 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -208,13 +208,11 @@ if ($ENV{TEST_LEI_ONESHOT}) {
 
 SKIP: { # real socket
         require_mods(qw(Cwd), my $nr = 105);
-        my $nfd = eval { require Socket::MsgHdr; 4 } //
-                        eval { require IO::FDPass; 1 } // do {
+        my $nfd = eval { require Socket::MsgHdr; 4 } // do {
                 require PublicInbox::Spawn;
                 PublicInbox::Spawn->can('send_cmd4') ? 4 : undef;
         } //
-        skip 'Socket::MsgHdr, IO::FDPass or Inline::C missing or unconfigured',
-                $nr;
+        skip 'Socket::MsgHdr or Inline::C missing or unconfigured', $nr;
 
         local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
         my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/$nfd.sock";