Skip to content

Commit

Permalink
fixed a few small timing bugs in WebSocket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 24, 2013
1 parent c64c463 commit 394f4e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Added data attribute to Mojo::URL.
- Improved documentation.
- Improved tests.
- Fixed a few small timing bugs in WebSocket tests.

3.96 2013-04-22
- Updated jQuery to version 2.0.
Expand Down
43 changes: 6 additions & 37 deletions t/mojo/websocket.t
Expand Up @@ -105,13 +105,7 @@ websocket '/subreq' => sub {
};

websocket '/echo' => sub {
my $self = shift;
$self->on(
message => sub {
my ($self, $msg) = @_;
$self->send($msg);
}
);
shift->on(message => sub { shift->send(shift) });
};

my $buffer = '';
Expand All @@ -125,13 +119,7 @@ websocket '/double_echo' => sub {
};

websocket '/squish' => sub {
my $self = shift;
$self->on(
message => sub {
my ($self, $msg) = @_;
$self->send(b($msg)->squish);
}
);
shift->on(message => sub { shift->send(b(shift)->squish) });
};

websocket '/dead' => sub { die 'i see dead processes' };
Expand All @@ -140,8 +128,7 @@ websocket '/foo' =>
sub { shift->rendered->res->code('403')->message("i'm a teapot") };

websocket '/close' => sub {
my $self = shift;
$self->on(message => sub { Mojo::IOLoop->remove(shift->tx->connection) });
shift->on(message => sub { Mojo::IOLoop->remove(shift->tx->connection) });
};

my $timeout;
Expand Down Expand Up @@ -220,13 +207,7 @@ $ua->start(
Mojo::IOLoop->stop;
}
);
$tx->on(
message => sub {
my ($tx, $msg) = @_;
$tx->finish if length $result;
$result .= $msg;
}
);
$tx->on(message => sub { $result .= pop });
$local = Mojo::IOLoop->stream($tx->connection)->handle->sockport;
}
);
Expand Down Expand Up @@ -290,13 +271,7 @@ $ua->websocket(
'/subreq' => sub {
my ($ua, $tx) = @_;
$code = $tx->res->code;
$tx->on(
message => sub {
my ($tx, $msg) = @_;
$result .= $msg;
$tx->finish if $msg eq 'test1';
}
);
$tx->on(message => sub { $result .= pop });
$tx->on(
finish => sub {
$finished += 4;
Expand Down Expand Up @@ -364,13 +339,7 @@ $ua->websocket(
'/subreq' => sub {
my ($ua, $tx) = @_;
$code2 = $tx->res->code;
$tx->on(
message => sub {
my ($tx, $msg) = @_;
$result2 .= $msg;
$tx->finish if $msg eq 'test1';
}
);
$tx->on(message => sub { $result2 .= pop });
$tx->on(
finish => sub {
$finished += 2;
Expand Down

0 comments on commit 394f4e6

Please sign in to comment.