Debian Codegraph @

t/07-reconnect.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 Time::HiResscip-perl cpan Redis-Fast 0.37 Time/HiRes/ qw(gettimeofday tv_interval);
8 use Redis::Fastscip-perl cpan Redis-Fast 0.37 Redis/Fast/;
9 use libscip-perl cpan Redis-Fast 0.37 lib/ 't/tlib';
10 use Test::SpawnRedisServerscip-perl cpan Redis-Fast 0.37 Test/SpawnRedisServer/;
11 use Net::EmptyPortscip-perl cpan Redis-Fast 0.37 Net/EmptyPort/ qw(empty_port);
12
13 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 };
14
15 my ($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(timeout => 1);
16 my $use_ssl = $t ? SSL_AVAILABLE : 0;
17
18 END {
19 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $c;
20 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
21 }
22
23 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'Command without connection, no reconnect' => sub {
24 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 0, server => $srv), 'connected to our test redis-server');
25 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit()., 'close connection to the server');
26
27 likescip-perl cpan Redis-Fast 0.37 main/like().(exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => 1) }, qr{Not connected to any server}, 'send ping without reconnect',);
28 };
29
30 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'Command without connection or timeout, with database change, with reconnect' => sub {
31 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 2, server => $srv), 'connected to our test redis-server');
32
33 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->selectscip-perl cpan Redis-Fast 0.37 Redis/Fast/select().(4), 'send command with reconnect');
34 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.), 'send command with reconnect');
35 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit()., 'close connection to the server');
36 isscip-perl cpan Redis-Fast 0.37 main/is().($r->getscip-perl cpan Redis-Fast 0.37 Redis/Fast/get().('reconnect'), $$scip-perl cpan Redis-Fast 0.37 main/$$., 'reconnect with read errors before write');
37 };
38
39
40 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'Pending commands fail on reconnection' => sub {
41 planscip-perl cpan Redis-Fast 0.37 main/plan().(skip_all => "Skipping pending command tests when using SSL") if $use_ssl;
42 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 10, server => $srv), 'connected to our test redis-server');
43
44 my $succeed_pending = 0;
45 my $failed_pending = 0;
46 $r->dbsizescip-perl cpan Redis-Fast 0.37 Redis/Fast/dbsize().(sub {
47 my ($ret, $err) = @_scip-perl cpan Redis-Fast 0.37 main/`@_`.;
48 printscip-perl cpan Redis-Fast 0.37 main/print(). "Error: $err\n";
49 if ($err) {
50 $failed_pending++;
51 } else {
52 $succeed_pending++;
53 }
54 });
55
56 _wait_for_redis_timeoutscip-perl cpan Redis-Fast 0.37 main/_wait_for_redis_timeout().();
57 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(foo => 'bar'), 'send command with reconnect');
58
59 isscip-perl cpan Redis-Fast 0.37 main/is().($succeed_pending, 0, 'Pending commands does not succeed on reconnection');
60 isscip-perl cpan Redis-Fast 0.37 main/is().($failed_pending, 1, 'Pending commands fail on reconnection');
61 };
62
63
64 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'INFO commands with extra logic triggers reconnect' => sub {
65 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 2, server => $srv), 'connected to our test redis-server');
66
67 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit()., 'close connection to the server');
68
69 my $info = $r->infoscip-perl cpan Redis-Fast 0.37 Redis/Fast/info().;
70 isscip-perl cpan Redis-Fast 0.37 main/is().(refscip-perl cpan Redis-Fast 0.37 main/ref(). $info, 'HASH', 'reconnect on INFO command');
71 };
72
73
74 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'KEYS commands with extra logic triggers reconnect' => sub {
75 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 2, server => $srv), 'connected to our test redis-server');
76
77 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->flushdbscip-perl cpan Redis-Fast 0.37 Redis/Fast/flushdb()., 'delete all keys');
78 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.), 'set known key');
79
80 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit()., 'close connection to the server');
81
82 my @keys = $r->keysscip-perl cpan Redis-Fast 0.37 Redis/Fast/keys().('*');
83 is_deeplyscip-perl cpan Redis-Fast 0.37 main/is_deeply().(\@keys, ['reconnect'], 'reconnect on KEYS command');
84 };
85
86
87 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'PING commands with extra logic triggers reconnect' => sub {
88 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 2, server => $srv), 'connected to our test redis-server');
89
90 _wait_for_redis_timeoutscip-perl cpan Redis-Fast 0.37 main/_wait_for_redis_timeout().();
91
92 my $res = $r->pingscip-perl cpan Redis-Fast 0.37 Redis/Fast/ping().;
93 okscip-perl cpan Redis-Fast 0.37 main/ok().($res, 'reconnect on PING command');
94
95 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit()., 'close connection to the server');
96 $res = $r->pingscip-perl cpan Redis-Fast 0.37 Redis/Fast/ping().;
97 okscip-perl cpan Redis-Fast 0.37 main/ok().(!$res, 'QUIT command disables reconnect on PING command');
98 };
99
100
101 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Bad commands don't trigger reconnect" => sub {
102 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 2, server => $srv), 'connected to our test redis-server');
103
104 my $prev_sock = $r->__sockscip-perl cpan Redis-Fast 0.37 Redis/Fast/__sock().;
105 likescip-perl cpan Redis-Fast 0.37 main/like().(
106 exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(bad => reconnect => 1) },
107 qr{ERR wrong number of arguments for 'set' command|ERR syntax error},
108 'Bad commands still die',
109 );
110 isscip-perl cpan Redis-Fast 0.37 main/is().($r->__sockscip-perl cpan Redis-Fast 0.37 Redis/Fast/__sock()., $prev_sock, "... and don't trigger a reconnect");
111 };
112
113
114 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'Reconnect code clears sockect ASAP' => sub {
115 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
116 _wait_for_redis_timeoutscip-perl cpan Redis-Fast 0.37 main/_wait_for_redis_timeout().();
117 isscip-perl cpan Redis-Fast 0.37 main/is().(exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->quitscip-perl cpan Redis-Fast 0.37 Redis/Fast/quit(). }, undef, "Quit doesn't die if we are already disconnected");
118 };
119
120
121 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Reconnect gives up after timeout" => sub {
122 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
123 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
124 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
125
126 my $t0 = [gettimeofday];
127 likescip-perl cpan Redis-Fast 0.37 main/like().(
128 exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => 1) },
129 qr{Could not connect to Redis server at},
130 'Eventually it gives up and dies',
131 );
132 okscip-perl cpan Redis-Fast 0.37 main/ok().(tv_intervalscip-perl cpan Redis-Fast 0.37 main/tv_interval().($t0) > 3, '... minimum value for the reconnect reached');
133 };
134
135 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Reconnect during transaction" => sub {
136 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
137 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
138
139 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
140 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
141 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
142
143 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().(), 'start transacion');
144 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect_1' => 1), 'set first key');
145
146 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
147 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
148 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
149
150 likescip-perl cpan Redis-Fast 0.37 main/like().(exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect_2' => 2) }, qr{reconnect disabled inside transaction}, 'set second key');
151
152 $r->connectscip-perl cpan Redis-Fast 0.37 Redis/Fast/connect().(); #reconnect
153 isscip-perl cpan Redis-Fast 0.37 main/is().($r->existsscip-perl cpan Redis-Fast 0.37 Redis/Fast/exists().('reconnect_1'), 0, 'key "reconnect_1" should not exist');
154 isscip-perl cpan Redis-Fast 0.37 main/is().($r->existsscip-perl cpan Redis-Fast 0.37 Redis/Fast/exists().('reconnect_2'), 0, 'key "reconnect_2" should not exist');
155 };
156
157 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "exec does not trigger reconnect" => sub {
158 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
159 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
160
161 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
162 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
163 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
164
165 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().(), 'start transacion');
166 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect_1' => 1), 'set first key');
167
168 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
169 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
170 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
171
172 likescip-perl cpan Redis-Fast 0.37 main/like().(exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->execscip-perl cpan Redis-Fast 0.37 Redis/Fast/exec().() }, qr{reconnect disabled inside transaction}, 'exec');
173
174 $r->connectscip-perl cpan Redis-Fast 0.37 Redis/Fast/connect().(); #reconnect
175 isscip-perl cpan Redis-Fast 0.37 main/is().($r->existsscip-perl cpan Redis-Fast 0.37 Redis/Fast/exists().('reconnect_1'), 0, 'key "reconnect_1" should not exist');
176 };
177
178 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "multi should trigger reconnect" => sub {
179 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
180 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
181
182 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
183 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
184 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
185
186 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
187 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
188 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
189
190 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().(), 'start transacion');
191 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'set key');
192 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->execscip-perl cpan Redis-Fast 0.37 Redis/Fast/exec().(), 'execute transaction');
193
194 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
195 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
196 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
197
198 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'setting key should not fail');
199 };
200
201 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Reconnect works after WATCH + MULTI + EXEC" => sub {
202 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
203 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
204
205 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
206 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
207 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
208
209 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('watch' => 'watch'), 'set watch key');
210 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->watchscip-perl cpan Redis-Fast 0.37 Redis/Fast/watch().('watch'), 'start watching key');
211 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().(), 'start transacion');
212 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'set key');
213 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->execscip-perl cpan Redis-Fast 0.37 Redis/Fast/exec().(), 'execute transaction');
214
215 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
216 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
217 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
218
219 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'setting key should not fail');
220 };
221
222 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Reconnect works after WATCH + MULTI + DISCARD" => sub {
223 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
224 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
225
226 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
227 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
228 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0, reconnect => 3, server => $srv), 'connected to our test redis-server');
229
230 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('watch' => 'watch'), 'set watch key');
231 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->watchscip-perl cpan Redis-Fast 0.37 Redis/Fast/watch().('watch'), 'start watching key');
232 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->multiscip-perl cpan Redis-Fast 0.37 Redis/Fast/multi().(), 'start transacion');
233 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'set key');
234 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->discardscip-perl cpan Redis-Fast 0.37 Redis/Fast/discard().(), 'dscard transaction');
235
236 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().;
237 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t;
238 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
239
240 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().('reconnect' => 1), 'setting second key should not fail');
241 };
242
243 subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). "Reconnect behaviour differs from cpan Redis module #73" => sub {
244 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
245 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
246
247 my $port = empty_portscip-perl cpan Redis-Fast 0.37 main/empty_port().();
248 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "spawn redis on port $port");
249
250 okscip-perl cpan Redis-Fast 0.37 main/ok().(my $r = Redis::Fast->newscip-perl cpan Redis-Fast 0.37 Redis/Fast/new().(ssl => $use_ssl, SSL_verify_mode => 0,
251 reconnect => 1,
252 every => 100_000,
253 cnx_timeout => 3,
254 read_timeout => 1,
255 write_timeout => 1,
256 server => $srv
257 ), 'connected to our test redis-server');
258 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.), 'send command');
259
260 $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`().; # Make previous server is dead
261 $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; # Close stunnel if using SSL
262
263 likescip-perl cpan Redis-Fast 0.37 main/like().(
264 exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.) },
265 qr{Could not connect to Redis server at},
266 'Eventually it gives up and dies (first try)',
267 );
268
269 likescip-perl cpan Redis-Fast 0.37 main/like().(
270 exceptionscip-perl cpan Redis-Fast 0.37 main/exception(). { $r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.) },
271 qr{Could not connect to Redis server at},
272 'Eventually it gives up and dies (second try)',
273 );
274
275 okscip-perl cpan Redis-Fast 0.37 main/ok().(($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(port => $port, timeout => 1), "respawn redis on port $port");
276 okscip-perl cpan Redis-Fast 0.37 main/ok().($r->setscip-perl cpan Redis-Fast 0.37 Redis/Fast/set().(reconnect => $$scip-perl cpan Redis-Fast 0.37 main/$$.), 'a command works after respawn');
277 };
278
279 done_testingscip-perl cpan Redis-Fast 0.37 main/done_testing().();
280
281
282 sub _wait_for_redis_timeoutscip-perl cpan Redis-Fast 0.37 main/_wait_for_redis_timeout(). {
283 ## Redis will timeout clients after 100 internal server loops, at
284 ## least 10 seconds (even with a timeout 1 on the config) so we sleep
285 ## a bit more hoping the timeout did happen. Not perfect, patches
286 ## welcome
287 diagscip-perl cpan Redis-Fast 0.37 main/diag().('Sleeping 11 seconds, waiting for Redis to timeout...');
288 sleepscip-perl cpan Redis-Fast 0.37 main/sleep().(11);
289 }