Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed another small timing bug in Mojo::IOLoop test
  • Loading branch information
kraih committed Aug 13, 2012
1 parent 132263f commit caa0866
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.29 2012-08-12
3.29 2012-08-13
- Improved documentation.
- Improved tests.
- Fixed small timing bugs in WebSocket and TLS tests.
Expand Down
23 changes: 12 additions & 11 deletions t/mojo/ioloop.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 33;
use Test::More tests => 32;

# "Marge, you being a cop makes you the man!
# Which makes me the woman, and I have no interest in that,
Expand Down Expand Up @@ -170,26 +170,27 @@ $loop->client(
$loop->start;
ok $err, 'has error';

# Removed connection
# Removed connection (with delay)
my $removed;
$delay = Mojo::IOLoop->delay(sub { $removed++ });
$port = Mojo::IOLoop->generate_port;
my ($server_close, $client_close);
$delay->begin;
Mojo::IOLoop->server(
(address => '127.0.0.1', port => $port) => sub {
my ($loop, $stream) = @_;
$stream->on(close => sub { $server_close++ });
$stream->on(close => sub { $delay->end });
}
);
$delay->begin;
$id = Mojo::IOLoop->client(
(port => $port) => sub {
my ($loop, $err, $stream) = @_;
$stream->on(close => sub { $client_close++ });
$stream->on(close => sub { $delay->end });
$loop->remove($id);
}
);
Mojo::IOLoop->timer(0.5 => sub { shift->stop });
Mojo::IOLoop->start;
is $server_close, 1, 'server emitted close event once';
is $client_close, 1, 'client emitted close event once';
$delay->wait;
is $removed, 1, 'connection has been removed';

# Stream throttling
$port = Mojo::IOLoop->generate_port;
Expand Down Expand Up @@ -239,7 +240,7 @@ is $client, 'works!', 'full message has been written';
$err = '';
$loop = Mojo::IOLoop->new(max_connections => 0);
$loop->remove($loop->client({port => $loop->generate_port}));
$loop->timer(1 => sub { shift->stop; $err = 'failed!' });
$loop->timer(1 => sub { shift->stop; $err = 'failed' });
$loop->start;
ok !$err, 'no error';
is $loop->max_connections, 0, 'right value';
Expand All @@ -251,7 +252,7 @@ $port = $loop->generate_port;
$loop->server(
{address => '127.0.0.1', port => $port} => sub { shift; shift->close });
$loop->client({port => $port} => sub { });
$loop->timer(1 => sub { shift->stop; $err = 'failed!' });
$loop->timer(1 => sub { shift->stop; $err = 'failed' });
$loop->start;
ok !$err, 'no error';
is $loop->max_accepts, 1, 'right value';
Expand Down

0 comments on commit caa0866

Please sign in to comment.