diff --git a/t/mojo/reactor_ev.t b/t/mojo/reactor_ev.t index 6837a9026b..1c894a6076 100644 --- a/t/mojo/reactor_ev.t +++ b/t/mojo/reactor_ev.t @@ -10,11 +10,10 @@ use Mojo::Util qw(steady_time); subtest 'With reactor' => sub { - my $reactor; - subtest 'Instantiation' => sub { use_ok 'Mojo::Reactor::EV'; - $reactor = Mojo::Reactor::EV->new; + + my $reactor = Mojo::Reactor::EV->new; is ref $reactor, 'Mojo::Reactor::EV', 'right object'; is ref Mojo::Reactor::EV->new, 'Mojo::Reactor::Poll', 'right object'; @@ -27,6 +26,8 @@ subtest 'With reactor' => sub { }; subtest 'Make sure it stops automatically when not watching for events' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; + my $triggered; Mojo::IOLoop->next_tick(sub { $triggered++ }); Mojo::IOLoop->start; @@ -42,6 +43,7 @@ subtest 'With reactor' => sub { my $listen = IO::Socket::INET->new(Listen => 5, LocalAddr => '127.0.0.1'); subtest 'Listen' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my ($readable, $writable); $reactor->io($listen => sub { pop() ? $writable++ : $readable++ })->watch($listen, 0, 0)->watch($listen, 1, 1); $reactor->timer(0.025 => sub { shift->stop }); @@ -56,6 +58,7 @@ subtest 'With reactor' => sub { subtest 'Connect' => sub { my ($readable, $writable); + my $reactor = Mojo::IOLoop->singleton->reactor; $reactor->io($listen => sub { pop() ? $writable++ : $readable++ })->watch($listen, 0, 0)->watch($listen, 1, 1); $reactor->timer(1 => sub { shift->stop }); $reactor->start; @@ -64,12 +67,13 @@ subtest 'With reactor' => sub { }; subtest 'With server' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; ok $reactor->remove($listen), 'removed'; ok !$reactor->remove($listen), 'not removed again'; my $server = $listen->accept; subtest 'Accept' => sub { - + my $reactor = Mojo::IOLoop->singleton->reactor; my ($readable, $writable); $reactor->io($client => sub { pop() ? $writable++ : $readable++ }); $reactor->again($reactor->timer(0.025 => sub { shift->stop })); @@ -119,6 +123,7 @@ subtest 'With reactor' => sub { }; subtest 'Timers' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my ($timer, $recurring); $reactor->timer(0 => sub { $timer++ }); ok $reactor->remove($reactor->timer(0 => sub { $timer++ })), 'removed'; @@ -175,6 +180,7 @@ subtest 'With reactor' => sub { }; subtest 'Reset' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; $reactor->next_tick(sub { die 'Reset failed' }); $reactor->reset; my ($readable, $writable, $recurring); @@ -189,6 +195,7 @@ subtest 'With reactor' => sub { }; subtest 'Ordered next_tick' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $result = []; for my $i (1 .. 10) { $reactor->next_tick(sub { push @$result, $i }); @@ -198,6 +205,7 @@ subtest 'With reactor' => sub { }; subtest 'Reset while watchers are active' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my ($writable); $reactor->io($_ => sub { ++$writable and shift->reset })->watch($_, 0, 1) for $client, $server; $reactor->start; @@ -205,6 +213,7 @@ subtest 'With reactor' => sub { }; subtest 'Concurrent reactors' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $timer = 0; $reactor->recurring(0 => sub { $timer++ }); my $timer2; @@ -237,6 +246,7 @@ subtest 'With reactor' => sub { }; subtest 'Restart timer' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my ($single, $pair, $one, $two, $last); $reactor->timer(0.025 => sub { $single++ }); $one = $reactor->timer( @@ -260,6 +270,7 @@ subtest 'With reactor' => sub { }; subtest 'Reset timer' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $before = steady_time; my ($after, $again); my ($one, $two); @@ -284,6 +295,7 @@ subtest 'With reactor' => sub { }; subtest 'Restart inactive timer' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $id = $reactor->timer(0 => sub { }); ok $reactor->remove($id), 'removed'; @@ -292,6 +304,7 @@ subtest 'With reactor' => sub { }; subtest 'Change inactive I/O watcher' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; ok !$reactor->remove($listen), 'not removed again'; eval { $reactor->watch($listen, 1, 1) }; @@ -299,6 +312,7 @@ subtest 'With reactor' => sub { }; subtest 'Error' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $err; $reactor->unsubscribe('error')->on( error => sub { @@ -312,6 +326,7 @@ subtest 'With reactor' => sub { }; subtest 'Reset events' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; $reactor->on(error => sub { }); ok $reactor->has_subscribers('error'), 'has subscribers'; @@ -320,6 +335,7 @@ subtest 'With reactor' => sub { }; subtest 'Recursion' => sub { + my $reactor = Mojo::IOLoop->singleton->reactor; my $timer; $reactor = $reactor->new; $reactor->timer(0 => sub { ++$timer and shift->one_tick });