Debian Codegraph @

t/04-pipeline.t

raw symbols SCIP
1 #!perl
2
3 use warningsscip-perl cpan Redis-Fast 0.37 warnings/;
4 use strictscip-perl cpan Redis-Fast 0.37 strict/;
5 use Test::Morescip-perl cpan Redis-Fast 0.37 Test/More/;
6 use Test::Fatalscip-perl cpan Redis-Fast 0.37 Test/Fatal/;
7 use Redis::Fastscip-perl cpan Redis-Fast 0.37 Redis/Fast/;
8 use libscip-perl cpan Redis-Fast 0.37 lib/ 't/tlib';
9 use Test::SpawnRedisServerscip-perl cpan Redis-Fast 0.37 Test/SpawnRedisServer/;
10 use Test::Deepscip-perl cpan Redis-Fast 0.37 Test/Deep/;
11
12 use constantscip-perl cpan Redis-Fast 0.37 constant/ SSL_AVAILABLEscip-perl cpan Redis-Fast 0.37 main/SSL_AVAILABLE(). => eval { requirescip-perl cpan Redis-Fast 0.37 main/require(). IO::Socket::SSL };
13
14 my ($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().();
15 my $use_ssl = $t ? SSL_AVAILABLE : 0;
16
17 END {
18 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $c;
19 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
20 }
21
22 {
23 my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(server => $srv, ssl => $use_ssl, SSL_verify_mode => 0);
24 eval { $r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().( ); };
25 planscip-perl cpan Redis-Fast 0.37 main/plan(). 'skip_all' => "multi without arguments not implemented on this redis server" if $@scip-perl cpan Redis-Fast 0.37 main/`$@`. && $@scip-perl cpan Redis-Fast 0.37 main/`$@`. =~ /unknown command/;
26 }
27
28
29 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(server => $srv, ssl => $use_ssl, SSL_verify_mode => 0), 'connected to our test redis-server');
30
31 sub pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). {
32 my ($desc, @commands) = @_scip-perl cpan Redis-Fast 0.37 main/`@_`.;
33 my (@responses, @expected_responses);
34 for my $cmd (@commands) {
35 my ($method, $args, $expected, $expected_err) = @$cmd;
36 pushscip-perl cpan Redis-Fast 0.37 main/push(). @expected_responses, [$expected, $expected_err];
37 $r->$methodscip-perl cpan Redis-Fast 0.37 Redis/Fast/$method().(@$args, sub { pushscip-perl cpan Redis-Fast 0.37 main/push(). @responses, [@_scip-perl cpan Redis-Fast 0.37 main/`@_`.] });
38 }
39 $r->wait_all_responsesscip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_all_responses().;
40
41 cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\@responses, \@expected_responses, $desc);
42 }
43
44 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'single-command pipeline', ([set => [foo => 'bar'], 'OK'],);
45
46 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'pipeline with embedded error',
47 ([set => [clunk => 'eth'], 'OK'], [oops => [], undef, rescip-perl cpan Redis-Fast 0.37 main/re().(q[\AERR unknown command ['`]OOPS['`](:?, with args beginning with: )?\z])], [get => ['clunk'], 'eth'],);
48
49 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'keys in pipelined mode',
50 ([keys => ['*'], bagscip-perl cpan Redis-Fast 0.37 main/bag().(qw<foo clunk>)], [keys => [], undef, q[ERR wrong number of arguments for 'keys' command]],);
51
52 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'info in pipelined mode',
53 (
54 [info => [], codescip-perl cpan Redis-Fast 0.37 main/code().(sub { refscip-perl cpan Redis-Fast 0.37 main/ref(). $_scip-perl cpan Redis-Fast 0.37 main/`@_`.[0] eq 'HASH' && keysscip-perl cpan Redis-Fast 0.37 main/keys(). %{ $_scip-perl cpan Redis-Fast 0.37 main/`@_`.[0] } })],
55 );
56
57 eval { $r->infoscip-perl cpan Redis-Fast 0.37 Redis/Fast/info().(qw<oops oops>); };
58 if ($@scip-perl cpan Redis-Fast 0.37 main/`$@`.) {
59 # from Redis 7.0, `info oops oops` returns an empty string instread of an error.
60 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'info error in pipelined mode',
61 (
62 [ info => [qw<oops oops>],
63 undef,
64 rescip-perl cpan Redis-Fast 0.37 main/re().(qr{^ERR (?:syntax error|wrong number of arguments for 'info' command)$})
65 ],
66 );
67 }
68
69 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'pipeline with multi-bulk reply',
70 ([hmset => [kapow => (a => 1, b => 2, c => 3)], 'OK'], [hmget => [kapow => qw<c b a>], [3, 2, 1]],);
71
72 pipeline_okscip-perl cpan Redis-Fast 0.37 main/pipeline_ok(). 'large pipeline',
73 (
74 (mapscip-perl cpan Redis-Fast 0.37 main/map(). { [hset => [zzapp => $_scip-perl cpan Redis-Fast 0.37 main/$_. => -$_scip-perl cpan Redis-Fast 0.37 main/$_.], 1] } 1 .. 5000),
75 [hmget => [zzapp => (1 .. 5000)], [reversescip-perl cpan Redis-Fast 0.37 main/reverse(). -5000 .. -1]],
76 [del => ['zzapp'], 1],
77 );
78
79 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'synchronous request with pending pipeline' => sub {
80 my $clunk;
81 isscip-perl cpan Redis-Fast 0.37 main/is().($r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('clunk', sub { $clunk = $_scip-perl cpan Redis-Fast 0.37 main/`@_`.[0] }), 1, 'queue a request');
82 isscip-perl cpan Redis-Fast 0.37 main/is().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('kapow', 'zzapp', sub { }), 1, 'queue another request');
83 isscip-perl cpan Redis-Fast 0.37 main/is().($r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('kapow'), 'zzapp', 'synchronous request has expected return');
84 isscip-perl cpan Redis-Fast 0.37 main/is().($clunk, 'eth', 'synchronous request processes pending ones');
85 };
86
87 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'transaction with error and pipeline' => sub {
88 my @responses;
89 my $s = sub { pushscip-perl cpan Redis-Fast 0.37 main/push(). @responses, [@_scip-perl cpan Redis-Fast 0.37 main/`@_`.] };
90 $r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().($s);
91 $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(clunk => 'eth', $s);
92 $r->rpushscip-perl cpan Redis-Fast 0.37 Redis/Fast/rpush().(clunk => 'oops', $s);
93 $r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('clunk', $s);
94 $r->execscip-perl cpan Redis-Fast 0.37 Redis/Fast/exec().($s);
95 $r->wait_all_responsesscip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_all_responses().;
96
97 isscip-perl cpan Redis-Fast 0.37 main/is().(shiftscip-perl cpan Redis-Fast 0.37 main/shift().(@responses)->[0], 'OK' , 'multi started' );
98 isscip-perl cpan Redis-Fast 0.37 main/is().(shiftscip-perl cpan Redis-Fast 0.37 main/shift().(@responses)->[0], 'QUEUED', 'queued');
99 isscip-perl cpan Redis-Fast 0.37 main/is().(shiftscip-perl cpan Redis-Fast 0.37 main/shift().(@responses)->[0], 'QUEUED', 'queued');
100 isscip-perl cpan Redis-Fast 0.37 main/is().(shiftscip-perl cpan Redis-Fast 0.37 main/shift().(@responses)->[0], 'QUEUED', 'queued');
101 my $resp = shiftscip-perl cpan Redis-Fast 0.37 main/shift(). @responses;
102 isscip-perl cpan Redis-Fast 0.37 main/is(). ($resp->[0]->[0]->[0], 'OK', 'set');
103 isscip-perl cpan Redis-Fast 0.37 main/is(). ($resp->[0]->[1]->[0], undef, 'bad rpush value should be undef');
104 likescip-perl cpan Redis-Fast 0.37 main/like(). ($resp->[0]->[1]->[1],
105 qr/(?:ERR|WRONGTYPE) Operation against a key holding the wrong kind of value/,
106 'bad rpush should give an error');
107 isscip-perl cpan Redis-Fast 0.37 main/is(). ($resp->[0]->[2]->[0], 'eth', 'get should work');
108 };
109
110 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'transaction with error and no pipeline' => sub {
111 isscip-perl cpan Redis-Fast 0.37 main/is().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi()., 'OK', 'multi');
112 isscip-perl cpan Redis-Fast 0.37 main/is().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('clunk', 'eth'), 'QUEUED', 'transactional SET');
113 isscip-perl cpan Redis-Fast 0.37 main/is().($r->rpushscip-perl cpan Redis-Fast 0.37 Redis/Fast/rpush().('clunk', 'oops'), 'QUEUED', 'transactional bad RPUSH');
114 isscip-perl cpan Redis-Fast 0.37 main/is().($r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('clunk'), 'QUEUED', 'transactional GET');
115 likescip-perl cpan Redis-Fast 0.37 main/like().(
116 exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->execscip-perl cpan Redis-Fast 0.37 Redis/Fast/exec(). },
117 qr{\[exec\] (?:WRONGTYPE|ERR) Operation against a key holding the wrong kind of value,},
118 'synchronous EXEC dies for intervening error'
119 );
120 };
121
122
123 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'wait_one_response' => sub {
124 planscip-perl cpan Redis-Fast 0.37 main/plan(). skip_all => 'hiredis cannot wait_one_response';
125 my $first;
126 my $second;
127
128 $r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('a', sub { $first++ });
129 $r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('a', sub { $second++ });
130 $r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('a', sub { $first++ });
131 $r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('a', sub { $second++ });
132
133 $r->wait_one_responsescip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_one_response().();
134 isscip-perl cpan Redis-Fast 0.37 main/is().($first, 1, 'after first wait_one_response(), first callback called');
135 isscip-perl cpan Redis-Fast 0.37 main/is().($second, undef, '... but not the second one');
136
137 $r->wait_one_responsescip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_one_response().();
138 isscip-perl cpan Redis-Fast 0.37 main/is().($first, 1, 'after second wait_one_response(), first callback was not called again');
139 isscip-perl cpan Redis-Fast 0.37 main/is().($second, 1, '... but the second one was called');
140
141 $r->wait_all_responsesscip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_all_responses().();
142 isscip-perl cpan Redis-Fast 0.37 main/is().($first, 2, 'after final wait_all_responses(), first callback was called again');
143 isscip-perl cpan Redis-Fast 0.37 main/is().($second, 2, '... the second one was also called');
144
145 $r->wait_one_responsescip-perl cpan Redis-Fast 0.37 Redis/Fast/wait_one_response().();
146 isscip-perl cpan Redis-Fast 0.37 main/is().($first, 2, 'after final wait_one_response(), first callback was not called again');
147 isscip-perl cpan Redis-Fast 0.37 main/is().($second, 2, '... nor was the second one');
148 };
149
150
151 done_testingscip-perl cpan Redis-Fast 0.37 main/done_testing().();