MCE-Shared
view release on metacpan or search on metacpan
t/07_shared_condvar.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use Test::More;
BEGIN {
plan skip_all => 'set TEST_CONDVAR to enable this test (developer only)!'
if ( $^O eq 'MSWin32' && $] lt '5.020000' && !$ENV{'TEST_CONDVAR'} );
use_ok 'MCE::Hobo';
use_ok 'MCE::Shared';
use_ok 'MCE::Shared::Condvar';
}
my $cv = MCE::Shared->condvar();
## One must explicitly start the shared-server for condvars and queues.
## Not necessary otherwise when IO::FDPass is available.
MCE::Shared->start() unless $INC{'IO/FDPass.pm'};
## signal - --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
{
ok( 1, "shared condvar, spawning an asynchronous process" );
my $proc = MCE::Hobo->new( sub {
sleep(1) for 1..2;
$cv->lock;
$cv->signal;
1;
});
$cv->lock;
$cv->wait;
ok( 1, "shared condvar, we've come back from the process" );
is( $proc->join, 1, 'shared condvar, check if process came back correctly' );
}
## lock, set, get, unlock - --- --- --- --- --- --- --- --- --- --- --- --- ---
{
my $data = 'beautiful skies, ...';
$cv->lock;
my $proc = MCE::Hobo->new( sub {
$cv->lock;
$cv->get eq $data;
});
$cv->set($data);
$cv->unlock;
ok( $proc->join, 'shared condvar, check if process sees the same value' );
}
## timedwait, wait, broadcast - --- --- --- --- --- --- --- --- --- --- --- ---
## the tests relocated to xt/condvar_timedwait in 1.884
## the rest --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
$cv->set(20);
is( $cv->len(), 2, 'shared condvar, check length' );
is( $cv->incr(), 21, 'shared condvar, check incr' );
( run in 2.230 seconds using v1.01-cache-2.11-cpan-800906f7e73 )