AnyEvent-RipeRedis
view release on metacpan or search on metacpan
t/09-conn-errors.t view on Meta::CPAN
isa_ok( $t_cmd_err_2, 'AnyEvent::RipeRedis::Error' );
is( $t_cmd_err_2->message,
q{Operation "ping" aborted: No connection to the server.},
"$t_npref; second command error message" );
is( $t_cmd_err_2->code, E_NO_CONN, "$t_npref; second command error code" );
return;
}
sub t_reconnection {
my $port = empty_port();
my $server_info = run_redis_instance(
port => $port,
);
SKIP: {
if ( !defined $server_info ) {
skip 'redis-server is required for this test', 6;
}
my $t_conn_cnt = 0;
my $t_disconn_cnt = 0;
my $t_cli_err;
my $redis;
AE::now_update();
ev_loop(
sub {
my $cv = shift;
$redis = AnyEvent::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
on_connect => sub {
$t_conn_cnt++;
},
on_disconnect => sub {
$t_disconn_cnt++;
$cv->send;
},
on_error => sub {
$t_cli_err = shift;
},
);
$redis->ping(
sub {
my $reply = shift;
my $err = shift;
if ( defined $err ) {
diag( $err->message );
$cv->send;
return;
}
my $timer;
$timer = AE::postpone(
sub {
undef $timer;
$server_info->{server}->stop;
}
);
}
);
}
);
$server_info = run_redis_instance(
port => $port,
);
my $t_pong;
ev_loop(
sub {
my $cv = shift;
$redis->ping(
sub {
$t_pong = shift;
my $err = shift;
if ( defined $err ) {
diag( $err->message );
$cv->send;
return;
}
$cv->send;
}
);
}
);
my $t_npref = 'reconnection';
is( $t_conn_cnt, 2, "$t_npref; connections" );
is( $t_disconn_cnt, 1, "$t_npref; disconnections" );
isa_ok( $t_cli_err, 'AnyEvent::RipeRedis::Error' );
is( $t_cli_err->message, 'Connection closed by remote host.',
"$t_npref; error message" );
is( $t_cli_err->code, E_CONN_CLOSED_BY_REMOTE_HOST, "$t_npref; error code" );
is( $t_pong, 'PONG', "$t_npref; success PING" );
$redis->disconnect;
}
return;
}
sub t_read_timeout {
my $server_info = run_redis_instance();
SKIP: {
if ( !defined $server_info ) {
skip 'redis-server is required for this test', 6;
}
my $redis;
( run in 0.460 second using v1.01-cache-2.11-cpan-02777c243ea )