AnyEvent-WebSocket-Client
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/anyevent_websocket_client.t view on Meta::CPAN
use lib 't/lib';
use Test2::Plugin::EV;
use Test2::Plugin::AnyEvent::Timeout;
use Test2::V0 -no_srand => 1;
use Test2::Tools::WebSocket::Server qw( start_server start_echo );
use AnyEvent::WebSocket::Client;
subtest 'new' => sub {
my $client = AnyEvent::WebSocket::Client->new;
isa_ok $client, 'AnyEvent::WebSocket::Client';
};
subtest 'tests against count server' => sub {
my $counter;
my $max;
my $last_handshake;
my $uri = start_server(
customize_server_response => sub {
my($handshake) = @_;
if($handshake->req->subprotocol)
{
note "sub protocols requested: @{[ $handshake->req->subprotocol ]}";
my %sb = map { $_ => 1 } split(/,/, $handshake->req->subprotocol);
if($sb{bar})
{
$handshake->res->subprotocol('bar');
}
if($sb{klingon})
{
$handshake->res->subprotocol('romulan');
}
}
},
handshake => sub { # handshake
my $opt = { @_ };
$counter = 1;
$max = 15;
note "max = $max";
$last_handshake = $opt->{handshake};
#note $opt->{handshake}->req->to_string;
#note $opt->{handshake}->to_string;
note "resource = " . $opt->{handshake}->req->resource_name;
note "version = " . $opt->{handshake}->version;
if($opt->{handshake}->req->resource_name =~ /\/count\/(\d+)/)
{ $max = $1 }
note "max = $max";
},
message => sub { # message
my $opt = { @_ };
eval q{
note "send $counter";
$opt->{hdl}->push_write($opt->{frame}->new($counter++)->to_bytes);
if($counter >= $max)
{
$opt->{hdl}->push_write($opt->{frame}->new(type => 'close')->to_bytes);
$opt->{hdl}->push_shutdown;
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.453 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )