IO-Async
view release on metacpan or search on metacpan
lib/IO/Async/LoopTests.pm view on Meta::CPAN
is_oneref( $loop, '$loop has refcount 1' );
__PACKAGE__->can( "run_tests_$test" )->();
is_oneref( $loop, '$loop has refcount 1 finally' );
}
done_testing;
}
sub wait_for(&)
{
# Bounce via here so we don't upset refcount tests by having loop
# permanently set in IO::Async::Test
IO::Async::Test::testing_loop( $loop );
# Override prototype - I know what I'm doing
&IO::Async::Test::wait_for( @_ );
IO::Async::Test::testing_loop( undef );
}
sub time_between(&$$$)
{
my ( $code, $lower, $upper, $name ) = @_;
my $start = time;
$code->();
my $took = ( time - $start ) / AUT;
cmp_ok( $took, '>=', $lower, "$name took at least $lower seconds" ) if defined $lower;
cmp_ok( $took, '<=', $upper * 3, "$name took no more than $upper seconds" ) if defined $upper;
if( $took > $upper and $took <= $upper * 3 ) {
lib/IO/Async/LoopTests.pm view on Meta::CPAN
}
=head2 process
Tests the Loop's support for watching child processes by PID
(Previously called C<child>)
=cut
sub run_in_child(&)
{
my $kid = fork;
defined $kid or die "Cannot fork() - $!";
return $kid if $kid;
shift->();
die "Fell out of run_in_child!\n";
}
sub run_tests_process
lib/IO/Async/Test.pm view on Meta::CPAN
The time in seconds to wait before giving up the test as being stalled.
Defaults to 10 seconds.
=back
=cut
our $Level = 0;
sub wait_for(&@)
{
my ( $cond, %opts ) = @_;
my ( undef, $callerfile, $callerline ) = caller( $Level );
my $timedout = 0;
my $timerid = $loop->watch_time(
after => $opts{timeout} // 10,
code => sub { $timedout = 1 },
);
lib/IO/Async/Test.pm view on Meta::CPAN
As C<wait_for>, but will also watch the given IO handle for readability, and
whenever it is readable will read bytes in from it into the given buffer. The
buffer is NOT initialised when the function is entered, in case data remains
from a previous call.
C<$buffer> can also be a CODE reference, in which case it will be invoked
being passed data read from the handle, whenever it is readable.
=cut
sub wait_for_stream(&$$)
{
my ( $cond, $handle, undef ) = @_;
my $on_read;
if( ref $_[2] eq "CODE" ) {
$on_read = $_[2];
}
else {
my $varref = \$_[2];
$on_read = sub { $$varref .= $_[0] };
( run in 0.304 second using v1.01-cache-2.11-cpan-49f99fa48dc )