Skip to content

Commit

Permalink
use after_fork hook instead of tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Jul 11, 2014
1 parent bee41ab commit ce1dd76
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions t/06-wait-all-children-with-timeout.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use strict;
use warnings;

use Fcntl qw/:flock/;
use File::Temp qw/tempfile/;
use Test::More tests => 4;

use Parallel::Prefork;
Expand All @@ -18,33 +17,24 @@ my $pm = Parallel::Prefork->new({
}
});

my ($fh, $filename) = tempfile;
syswrite $fh, '0', 1;
close $fh;
my $sig_retain_cnt = 1;
$pm->after_fork(sub {
$sig_retain_cnt++;
});

my $manager_pid = $$;

until ($pm->signal_received) {
$pm->start and next;

open my $fh, '+<', $filename
or die "failed to open temporary file: $filename: ";
flock $fh, LOCK_EX;
sysread $fh, my $c, 10;
$c++;
seek $fh, 0, 0;
syswrite $fh, $c, length($c);
flock $fh, LOCK_UN;
close $fh;

my $rcv = 0;
local $SIG{TERM} = sub { $rcv++ };

if ($c == $pm->max_workers) {
if ($sig_retain_cnt == $pm->max_workers) {
kill 'TERM', $manager_pid;
}

1 while $rcv < $c;
1 while $rcv < $sig_retain_cnt;

$pm->finish;
}
Expand All @@ -56,5 +46,3 @@ $pm->wait_all_children();
is $pm->num_workers, 0, 'all workers reaped.';

is($reaped, $pm->max_workers, "properly called on_child_reap callback");

unlink $filename;

0 comments on commit ce1dd76

Please sign in to comment.