EV-Redis
view release on metacpan or search on metacpan
t/flow_control.t view on Meta::CPAN
# Edge case: nested commands from within callback with max_pending
{
$r->connect_unix( $connect_info{sock} );
$r->max_pending(1);
my @results;
$r->command('set', 'nested_1', 'val1', sub {
push @results, ['cmd1', @_];
# Issue more commands from within callback
$r->command('set', 'nested_2', 'val2', sub {
push @results, ['cmd2', @_];
$r->command('set', 'nested_3', 'val3', sub {
push @results, ['cmd3', @_];
$r->disconnect;
});
});
});
EV::run;
is scalar(@results), 3, 'all 3 nested callbacks executed';
for my $res (@results) {
is $res->[1], 'OK', "$res->[0] succeeded";
}
$r->max_pending(0);
}
# Edge case: disconnect with pending/waiting commands clears waiting
{
$r->connect_unix( $connect_info{sock} );
$r->max_pending(1);
my @results;
$r->command('set', 'dc_wait_1', 'val1', sub {
push @results, ['cmd1', @_];
# Disconnect while cmd2 is waiting
$r->disconnect;
});
$r->command('set', 'dc_wait_2', 'val2', sub {
push @results, ['cmd2', @_];
});
is $r->waiting_count, 1, 'cmd2 is waiting';
EV::run;
is scalar(@results), 2, 'both callbacks executed';
is $results[0][0], 'cmd1', 'cmd1 first';
is $results[0][1], 'OK', 'cmd1 succeeded';
is $results[1][0], 'cmd2', 'cmd2 second';
is $results[1][2], 'disconnected', 'cmd2 got disconnect error';
$r->max_pending(0);
}
# Edge case: reconnect after disconnect (separate event loop iterations)
{
$r->connect_unix( $connect_info{sock} );
my @results;
$r->command('set', 'recon_1', 'val1', sub {
push @results, ['cmd1', @_];
$r->disconnect;
});
EV::run;
is $results[0][1], 'OK', 'cmd1 succeeded before disconnect';
# Now reconnect in a new event loop iteration
$r->connect_unix( $connect_info{sock} );
$r->command('set', 'recon_2', 'val2', sub {
push @results, ['cmd2', @_];
$r->disconnect;
});
EV::run;
is scalar(@results), 2, 'both callbacks executed';
is $results[1][0], 'cmd2', 'cmd2 executed after reconnect';
is $results[1][1], 'OK', 'cmd2 succeeded';
}
# Edge case: max_pending = 1 (single command at a time)
{
$r->connect_unix( $connect_info{sock} );
$r->max_pending(1);
my @results;
my @order;
for my $i (1..5) {
$r->command('set', "single_$i", "val$i", sub {
push @order, $i;
push @results, ["cmd$i", @_];
$r->disconnect if $i == 5;
});
}
is $r->pending_count, 1, 'only 1 pending';
is $r->waiting_count, 4, '4 waiting';
EV::run;
is scalar(@results), 5, 'all 5 callbacks executed';
is_deeply \@order, [1, 2, 3, 4, 5], 'commands executed in order';
for my $res (@results) {
is $res->[1], 'OK', "$res->[0] succeeded";
}
$r->max_pending(0);
}
# Edge case: command issued right after disconnect (before reconnect)
{
( run in 0.518 second using v1.01-cache-2.11-cpan-71847e10f99 )