Async-Event-Interval
view release on metacpan or search on metacpan
t/09-locking.t view on Meta::CPAN
require POSIX;
POSIX::_exit(0);
}
push @kids, $pid;
waitpid $_, 0 for @kids;
my $v = $e->interval;
ok $v == 100 || $v == 200,
"concurrent interval() setters produce an expected value, got $v "
. "(no corruption across $iters iterations x 2 children)";
}
# A LOCK_EX writer must block a LOCK_SH reader. Verify by holding
# LOCK_EX in a forked child and watching the parent's LOCK_SH wait
# for it.
{
my $knot = events_knot;
pipe my $child_ready_r, my $child_ready_w or die "pipe: $!";
t/09-locking.t view on Meta::CPAN
my $e = Async::Event::Interval->new(0.001, sub {
$cb_count++;
die "death-after-runs\n" if $cb_count >= 3;
});
$e->start;
is $cb_count, 3, "interval mode (death after runs): callback ran 3 times";
is scalar @finish_calls, 1,
"interval mode (death after runs): finish called exactly once";
is $finish_calls[0], 1, "...with exit code 1";
is $e->runs, 3, "runs incremented for all iterations including the dying one";
is $e->errors, 1, "errors incremented exactly once";
like $e->error_message, qr/death-after-runs/,
"interval mode (death after runs): error_message captured";
$e->_pid(0);
}
# Multiple events crashing independently each receive their own finish(1)
# call. The mocked start() returns 0 on odd calls (child path) and 1 on
# even calls (parent path), so each event's for(0..1) loop runs once
t/53-timeout.t view on Meta::CPAN
select(undef, undef, undef, 5);
});
$e->timeout(1);
$e->start;
select(undef, undef, undef, 2);
is $e->errors, 1, "run-once over timeout: errors incremented";
like $e->error_message, qr/Callback timed out after 1 second/,
"run-once over timeout: error_message records timeout";
}
# Interval mode: callback completes under timeout, multiple iterations.
{
my $count = 0;
my $e = Async::Event::Interval->new(0.1, sub { $count++ });
$e->timeout(2);
$e->start;
select(undef, undef, undef, 0.5);
$e->stop;
cmp_ok $e->runs, '>=', 2, "interval under timeout: ran at least twice";
is $e->errors, 0, "interval under timeout: no errors";
}
( run in 1.824 second using v1.01-cache-2.11-cpan-96521ef73a4 )