X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fipc.t;h=ca88eb59d4ed8fe4dc16fcd2d24ea7c973e060c6;hb=3b2b02a411b161e2392c3a5b1c376c83573b027e;hp=345024bd9038e3bcab03e9cce205305b4211226c;hpb=fb8b16ff2b40ecd22ebbdea0d27069749e800077;p=public-inbox.git diff --git a/t/ipc.t b/t/ipc.t index 345024bd..ca88eb59 100644 --- a/t/ipc.t +++ b/t/ipc.t @@ -9,6 +9,7 @@ use Fcntl qw(SEEK_SET); use Digest::SHA qw(sha1_hex); require_mods(qw(Storable||Sereal)); require_ok 'PublicInbox::IPC'; +my ($tmpdir, $for_destroy) = tmpdir(); state $once = eval <<''; package PublicInbox::IPC; use strict; @@ -31,6 +32,12 @@ sub test_sha { print { $self->{1} } sha1_hex($buf), "\n"; $self->{1}->flush; } +sub test_append_pid { + my ($self, $file) = @_; + open my $fh, '>>', $file or die "open: $!"; + $fh->autoflush(1); + print $fh "$$\n" or die "print: $!"; +} 1; my $ipc = bless {}, 'PublicInbox::IPC'; @@ -83,11 +90,8 @@ $test->('local'); defined($pid) or BAIL_OUT 'no spawn, no test'; is($ipc->ipc_do('test_pid'), $pid, 'worker pid returned'); $test->('worker'); - { - my ($tmp, $for_destroy) = tmpdir(); - $ipc->ipc_lock_init("$tmp/lock"); - is($ipc->ipc_do('test_pid'), $pid, 'worker pid returned'); - } + $ipc->ipc_lock_init("$tmpdir/lock"); + is($ipc->ipc_do('test_pid'), $pid, 'worker pid returned'); $ipc->ipc_worker_stop; ok(!kill(0, $pid) && $!{ESRCH}, 'worker stopped'); } @@ -167,18 +171,21 @@ SKIP: { $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_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_broadcast('test_append_pid', "$tmpdir/append_pid"); $ipc->wq_close; + open my $fh, '<', "$tmpdir/append_pid" or BAIL_OUT "open: $!"; + chomp(my @pids = <$fh>); + my %pids = map { $_ => 1 } grep(/\A[0-9]+\z/, @pids); + is(scalar keys %pids, 2, 'broadcast hit both PIDs'); is($ipc->wq_workers, undef, 'workers undef after close'); }