Beam-Runner

 view release on metacpan or  search on metacpan

t/timeout/alarm.t  view on Meta::CPAN


=head1 DESCRIPTION

This file tests the L<Beam::Runnable::Timeout::Alarm> class to ensure it
times out correctly.

=head1 SEE ALSO

L<Beam::Runnable::Timeout::Alarm>

=cut

use strict;
use warnings;
use Test::More;

my $RUNNING = 1;
{ package
        t::Timeout::Alarm;
    use Moo;
    with 'Beam::Runnable', 'Beam::Runnable::Timeout::Alarm';
    sub run {
        while ( $RUNNING ) { sleep 1 }
    }
}

subtest 'test timeout' => sub {
    my $flag = 0;
    my $foo = t::Timeout::Alarm->new(
        timeout => 0.1,
        _timeout_cb => sub {
            $RUNNING = 0;
        },
    );
    $foo->run;
    ok !$RUNNING, 'timeout reached';
};

done_testing;



( run in 0.488 second using v1.01-cache-2.11-cpan-99c4e6809bf )