Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better WebSocket event test
  • Loading branch information
kraih committed Oct 11, 2011
1 parent 930c0d9 commit 4e8f058
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions t/mojolicious/websocket_lite_app.t
Expand Up @@ -64,21 +64,19 @@ websocket '/bytes' => sub {
);
};

# WebSocket /double
websocket '/double' => sub {
# WebSocket /once
websocket '/once' => sub {
my $self = shift;
$self->on_message(
sub {
my ($self, $message) = @_;
$self->send_message("ONE: $message");
}
);
my $cb;
$cb = $self->on_message(
sub {
my ($self, $message) = @_;
$self->tx->once(
message => sub {
my ($tx, $message) = @_;
$self->send_message("TWO: $message");
$self->tx->unsubscribe(message => $cb);
}
);
};
Expand Down Expand Up @@ -169,11 +167,11 @@ $t->websocket_ok('/bytes')->send_message_ok([$bytes])->message_is($bytes)
$t->websocket_ok('/bytes')->send_message_ok([$bytes])->message_is($bytes)
->send_message_ok([$bytes])->message_is($bytes)->finish_ok;

# WebSocket /double
$t->websocket_ok('/double')->send_message_ok('hello')
->message_is('ONE: hello')->message_is('TWO: hello')
->send_message_ok('hello')->message_is('ONE: hello')
->send_message_ok('hello')->message_is('ONE: hello')->finish_ok;
# WebSocket /once
$t->websocket_ok('/once')->send_message_ok('hello')->message_is('ONE: hello')
->message_is('TWO: hello')->send_message_ok('hello')
->message_is('ONE: hello')->send_message_ok('hello')
->message_is('ONE: hello')->finish_ok;

# WebSocket /nested
$t->websocket_ok('/nested')->send_message_ok('hello')
Expand Down

0 comments on commit 4e8f058

Please sign in to comment.