Navigation Menu

Skip to content

Commit

Permalink
added stream throttling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 11, 2011
1 parent 7483dc8 commit e26d347
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.38 2011-12-11 00:00:00
- Improved tests.

2.37 2011-12-10 00:00:00
- Welcome to the Mojolicious core team Marcus Ramberg, Glen Hinkle
and Abhijit Menon-Sen.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.37';
our $VERSION = '2.38';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
46 changes: 45 additions & 1 deletion t/mojo/ioloop.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 28;
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 @@ -207,6 +207,50 @@ Mojo::IOLoop->start;
is $server_close, 1, 'server emitted close event once';
is $client_close, 1, 'client emitted close event once';

# Stream throttling
$port = Mojo::IOLoop->generate_port;
my ($client, $server, $client_after, $server_before, $server_after) = '';
Mojo::IOLoop->server(
{port => $port} => sub {
my ($loop, $stream) = @_;
$stream->on(
read => sub {
my ($stream, $chunk) = @_;
Mojo::IOLoop->timer(
'0.5' => sub {
$server_before = $server;
$stream->pause;
$stream->write('works!');
Mojo::IOLoop->timer(
'0.5' => sub {
$server_after = $server;
$client_after = $client;
$stream->resume;
Mojo::IOLoop->timer('0.5' => sub { Mojo::IOLoop->stop });
}
);
}
) unless $server;
$server .= $chunk;
}
);
}
);
Mojo::IOLoop->client(
{port => $port} => sub {
my ($loop, $stream) = @_;
my $drain;
$drain = sub { shift->write('1', $drain) };
$stream->$drain();
$stream->on(read => sub { $client .= pop });
}
);
Mojo::IOLoop->start;
is $server_before, $server_after, 'stream has been paused';
ok length($server) > length($server_after), 'stream has been resumed';
is $client, $client_after, 'stream was writable while paused';
is $client, 'works!', 'full message has been written';

# Defaults
is Mojo::IOLoop::Client->new->iowatcher, Mojo::IOLoop->singleton->iowatcher,
'right default';
Expand Down
1 change: 1 addition & 0 deletions t/mojo/ioloop_tls.t
Expand Up @@ -40,6 +40,7 @@ plan tests => 21;
# To the panic room store!"
use_ok 'Mojo::IOLoop';

# Built-in certificate
my $loop = Mojo::IOLoop->new;
my $port = Mojo::IOLoop->generate_port;
my ($server, $client) = '';
Expand Down

0 comments on commit e26d347

Please sign in to comment.