perl -Ilib t/05_mce_child.t
...
ok 2 - spawning asynchronously
ok 3 - check for unique pids
ok 4 - check list_running
ok 5 - check list_joinable
ok 6 - check list
ok 7 - check pending
ok 8 - check is_running child1
ok 9 - check is_joinable child1
ok 10 - check is_running child2
ok 11 - check is_joinable child2
ok 12 - check is_running child3
ok 13 - check is_joinable child3
...
Is there an alternative to sleep on the Windows platform, ensuring delay before the workers exit?
{
my ( $cnt, @list, %pids, %ret ); local $_;
my ( $come_then_i_pray ) = ( "さあ、私{
+99;祈る" . "Ǣ" );
ok( 1, "spawning asynchronously" ); # test 2
MCE::Child->create( sub { sleep 1; sleep 1; "$come_then_i_pray $_"
+} ) for ( 1..3 );
%pids = map { $_ => undef } MCE::Child->list_pids;
is ( scalar( keys %pids ), 3, 'check for unique pids' ); # test 3
@list = MCE::Child->list_running;
is ( scalar @list, 3, 'check list_running' ); # test 4
@list = MCE::Child->list_joinable;
is ( scalar @list, 0, 'check list_joinable' ); # test 5
@list = MCE::Child->list;
is ( scalar @list, 3, 'check list' ); # test 6
is ( MCE::Child->pending, 3, 'check pending' ); # test 7
$cnt = 0;
for ( @list ) {
++$cnt;
is ( $_->is_running, 1, 'check is_running child'.$cnt ); # te
+sts 8, 10, 12
is ( $_->is_joinable, '', 'check is_joinable child'.$cnt ); # te
+sts 9, 11, 13
}
$cnt = 0;
for ( @list ) {
++$cnt; $ret{ $_->join } = 1;
is ( $_->error, undef, 'check error child'.$cnt );
}
is ( scalar keys %ret, 3, 'check for unique values' );
for ( sort keys %ret ) {
my $id = chop; s/ $//;
is ( $_, $come_then_i_pray, "check for utf8 string $id" );
};
}
Update 1: I have an idea to not use sleep. Instead, I will have workers read a channel. The manager process will notify workers to exit after completing tests list_running, list_joinable, list, pending, is_running, and is_joinable.
Update 2: Released MCE 1.883 on meta::cpan
|