Skip to content

Commit

Permalink
more WebSocket frame tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 2, 2012
1 parent e92cab6 commit c0dacfe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.93 2012-05-01
2.93 2012-05-03
- Improved documentation.
- Improved tests.

2.92 2012-04-30
- Added commands attribute to Mojolicious.
Expand Down
22 changes: 1 addition & 21 deletions t/mojo/websocket.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 49;
use Test::More tests => 48;

# "I can't believe it! Reading and writing actually paid off!"
use IO::Socket::INET;
Expand Down Expand Up @@ -481,26 +481,6 @@ $ua->websocket(
$loop->start;
is $result, 'hi!' x 100, 'right result';

# WebSocket /echo (64bit length)
$result = undef;
$ua->websocket(
'/echo' => sub {
my $tx = pop;
$tx->max_websocket_size(500000);
$tx->on(finish => sub { $loop->stop });
$tx->on(
message => sub {
my ($tx, $message) = @_;
$result = $message;
$tx->finish;
}
);
$tx->send('hi' x 200000);
}
);
$loop->start;
is $result, 'hi' x 200000, 'right result';

# WebSocket /timeout
my $log = '';
$message = app->log->subscribers('message')->[0];
Expand Down
26 changes: 25 additions & 1 deletion t/mojo/websocket_frames.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

# "Being eaten by crocodile is just like going to sleep...
# in a giant blender."
use Test::More tests => 70;
use Test::More tests => 84;

use Mojo::Transaction::WebSocket;

Expand Down Expand Up @@ -134,3 +134,27 @@ is $frame->[3], 0, 'rsv3 flag is not set';
is $frame->[4], 2, 'binary frame';
is $frame->[5], 'a', 'right payload';
is $bytes = $ws->build_frame(1, 0, 0, 0, 2, 'a'), $bytes, 'frames are equal';

# 16bit text frame roundtrip
$ws = Mojo::Transaction::WebSocket->new;
$bytes = $ws->build_frame(1, 0, 0, 0, 1, 'hi' x 10000);
$frame = $ws->parse_frame(\($dummy = $bytes));
is $frame->[0], 1, 'fin flag is set';
is $frame->[1], 0, 'rsv1 flag is not set';
is $frame->[2], 0, 'rsv2 flag is not set';
is $frame->[3], 0, 'rsv3 flag is not set';
is $frame->[4], 1, 'text frame';
is $frame->[5], 'hi' x 10000, 'right payload';
is $ws->build_frame(1, 0, 0, 0, 1, 'hi' x 10000), $bytes, 'frames are equal';

# 64bit text frame roundtrip
$ws = Mojo::Transaction::WebSocket->new(max_websocket_size => 500000);
$bytes = $ws->build_frame(1, 0, 0, 0, 1, 'hi' x 200000);
$frame = $ws->parse_frame(\($dummy = $bytes));
is $frame->[0], 1, 'fin flag is set';
is $frame->[1], 0, 'rsv1 flag is not set';
is $frame->[2], 0, 'rsv2 flag is not set';
is $frame->[3], 0, 'rsv3 flag is not set';
is $frame->[4], 1, 'text frame';
is $frame->[5], 'hi' x 200000, 'right payload';
is $ws->build_frame(1, 0, 0, 0, 1, 'hi' x 200000), $bytes, 'frames are equal';

0 comments on commit c0dacfe

Please sign in to comment.