Skip to content

Commit

Permalink
test when the drain event gets emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 11, 2016
1 parent a8b45c0 commit b95fb6f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion t/mojolicious/longpolling_lite_app.t
Expand Up @@ -93,6 +93,18 @@ get '/longpoll/nolength' => sub {
);
};

get '/longpoll/order' => sub {
my $c = shift;
$c->write_chunk(
'First, ' => sub {
my $c = shift;
$c->stash->{order} -= 1;
$c->write_chunk('second, ' => sub { shift->finish('third!') });
}
);
$c->stash->{order} = 2;
};

get '/longpoll/static' => sub {
my $c = shift;
$c->cookie(bar => 'baz');
Expand Down Expand Up @@ -245,6 +257,14 @@ $t->get_ok('/longpoll/nolength')->status_is(200)
->content_is('hi there, what length?');
ok !$t->tx->keep_alive, 'connection will not be kept alive';

# The drain event should be emitted on the next reactor tick
$stash = undef;
$t->app->plugins->once(before_dispatch => sub { $stash = shift->stash });
$t->get_ok('/longpoll/order')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_is('First, second, third!');
is $stash->{order}, 1, 'the drain event was emitted on the next reactor tick';

# Static file with cookies and session
$log = '';
$cb = $t->app->log->on(message => sub { $log .= pop });
Expand All @@ -268,7 +288,6 @@ $stash = undef;
$t->app->plugins->once(before_dispatch => sub { $stash = shift->stash });
$t->get_ok('/stream')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('0123456789');
Mojo::IOLoop->one_tick until $stash->{destroyed};
is $stash->{subscribers}, 0, 'no leaking subscribers';
ok $stash->{destroyed}, 'controller has been destroyed';

Expand Down

0 comments on commit b95fb6f

Please sign in to comment.