summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/wait.tcl
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
commitdcacc00e3750300617ba6e16eb346713f91a783a (patch)
tree38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/tests/unit/wait.tcl
parent58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff)
downloadcrep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz
Remove testing data
Diffstat (limited to 'examples/redis-unstable/tests/unit/wait.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/wait.tcl528
1 files changed, 0 insertions, 528 deletions
diff --git a/examples/redis-unstable/tests/unit/wait.tcl b/examples/redis-unstable/tests/unit/wait.tcl
deleted file mode 100644
index 7cf849b..0000000
--- a/examples/redis-unstable/tests/unit/wait.tcl
+++ /dev/null
@@ -1,528 +0,0 @@
1source tests/support/cli.tcl
2
3start_server {tags {"wait network external:skip"}} {
4start_server {} {
5 set slave [srv 0 client]
6 set slave_host [srv 0 host]
7 set slave_port [srv 0 port]
8 set slave_pid [srv 0 pid]
9 set master [srv -1 client]
10 set master_host [srv -1 host]
11 set master_port [srv -1 port]
12
13 test {Setup slave} {
14 $slave slaveof $master_host $master_port
15 wait_for_condition 50 100 {
16 [s 0 master_link_status] eq {up}
17 } else {
18 fail "Replication not started."
19 }
20 }
21
22 test {WAIT out of range timeout (milliseconds)} {
23 # Timeout is parsed as milliseconds by getLongLongFromObjectOrReply().
24 # Verify we get out of range message if value is behind LLONG_MAX
25 # (decimal value equals to 0x8000000000000000)
26 assert_error "*or out of range*" {$master wait 2 9223372036854775808}
27
28 # expected to fail by later overflow condition after addition
29 # of mstime(). (decimal value equals to 0x7FFFFFFFFFFFFFFF)
30 assert_error "*timeout is out of range*" {$master wait 2 9223372036854775807}
31
32 assert_error "*timeout is negative*" {$master wait 2 -1}
33 }
34
35 test {WAIT should acknowledge 1 additional copy of the data} {
36 $master set foo 0
37 $master incr foo
38 $master incr foo
39 $master incr foo
40 assert {[$master wait 1 5000] == 1}
41 assert {[$slave get foo] == 3}
42 }
43
44 test {WAIT should not acknowledge 2 additional copies of the data} {
45 $master incr foo
46 assert {[$master wait 2 1000] <= 1}
47 }
48
49 test {WAIT should not acknowledge 1 additional copy if slave is blocked} {
50 pause_process $slave_pid
51 $master set foo 0
52 $master incr foo
53 $master incr foo
54 $master incr foo
55 assert {[$master wait 1 1000] == 0}
56 resume_process $slave_pid
57 assert {[$master wait 1 1000] == 1}
58 }
59
60 test {WAIT implicitly blocks on client pause since ACKs aren't sent} {
61 pause_process $slave_pid
62 $master multi
63 $master incr foo
64 $master client pause 10000 write
65 $master exec
66 assert {[$master wait 1 1000] == 0}
67 $master client unpause
68 resume_process $slave_pid
69 assert {[$master wait 1 1000] == 1}
70 }
71
72 test {WAIT replica multiple clients unblock - reuse last result} {
73 set rd [redis_deferring_client -1]
74 set rd2 [redis_deferring_client -1]
75
76 pause_process $slave_pid
77
78 $rd incr foo
79 $rd read
80
81 $rd2 incr foo
82 $rd2 read
83
84 $rd wait 1 0
85 $rd2 wait 1 0
86 wait_for_blocked_clients_count 2 100 10 -1
87
88 resume_process $slave_pid
89
90 assert_equal [$rd read] {1}
91 assert_equal [$rd2 read] {1}
92
93 $rd ping
94 assert_equal [$rd read] {PONG}
95 $rd2 ping
96 assert_equal [$rd2 read] {PONG}
97
98 $rd close
99 $rd2 close
100 }
101}}
102
103
104tags {"wait aof network external:skip"} {
105 start_server {overrides {appendonly {yes} auto-aof-rewrite-percentage {0}}} {
106 set master [srv 0 client]
107
108 test {WAITAOF local copy before fsync} {
109 r config set appendfsync no
110 $master incr foo
111 assert_equal [$master waitaof 1 0 50] {0 0} ;# exits on timeout
112 r config set appendfsync everysec
113 }
114
115 test {WAITAOF local copy everysec} {
116 $master incr foo
117 assert_equal [$master waitaof 1 0 0] {1 0}
118 }
119
120 test {WAITAOF local copy with appendfsync always} {
121 r config set appendfsync always
122 $master incr foo
123 assert_equal [$master waitaof 1 0 0] {1 0}
124 }
125
126 test {WAITAOF local wait and then stop aof} {
127 r config set appendfsync no
128 set rd [redis_deferring_client]
129 $rd incr foo
130 $rd read
131 $rd waitaof 1 0 0
132 wait_for_blocked_client
133 r config set appendonly no ;# this should release the blocked client as an error
134 assert_error {ERR WAITAOF cannot be used when numlocal is set but appendonly is disabled.} {$rd read}
135 $rd close
136 }
137
138 test {WAITAOF local on server with aof disabled} {
139 $master incr foo
140 assert_error {ERR WAITAOF cannot be used when numlocal is set but appendonly is disabled.} {$master waitaof 1 0 0}
141 }
142
143 test {WAITAOF local client unblock with timeout and error} {
144 r config set appendonly yes
145 r config set appendfsync no
146 set rd [redis_deferring_client]
147 $rd client id
148 set client_id [$rd read]
149
150 # Test unblock with timeout
151 $rd incr foo
152 $rd read
153 $rd waitaof 1 0 0
154 wait_for_blocked_client
155 assert_equal 1 [r client unblock $client_id timeout]
156
157 # Test unblock with error
158 $rd incr foo
159 $rd read
160 $rd waitaof 1 0 0
161 wait_for_blocked_client
162 assert_equal 1 [r client unblock $client_id error]
163 $rd close
164 }
165
166 test {WAITAOF local if AOFRW was postponed} {
167 r config set appendfsync everysec
168
169 # turn off AOF
170 r config set appendonly no
171
172 # create an RDB child that takes a lot of time to run
173 r set x y
174 r config set rdb-key-save-delay 100000000 ;# 100 seconds
175 r bgsave
176 assert_equal [s rdb_bgsave_in_progress] 1
177
178 # turn on AOF
179 r config set appendonly yes
180 assert_equal [s aof_rewrite_scheduled] 1
181
182 # create a write command (to increment master_repl_offset)
183 r set x y
184
185 # reset save_delay and kill RDB child
186 r config set rdb-key-save-delay 0
187 catch {exec kill -9 [get_child_pid 0]}
188
189 # wait for AOF (will unblock after AOFRW finishes)
190 assert_equal [r waitaof 1 0 10000] {1 0}
191
192 # make sure AOFRW finished
193 assert_equal [s aof_rewrite_in_progress] 0
194 assert_equal [s aof_rewrite_scheduled] 0
195 }
196
197 $master config set appendonly yes
198 waitForBgrewriteaof $master
199
200 start_server {overrides {appendonly {yes} auto-aof-rewrite-percentage {0}}} {
201 set master_host [srv -1 host]
202 set master_port [srv -1 port]
203 set replica [srv 0 client]
204 set replica_host [srv 0 host]
205 set replica_port [srv 0 port]
206 set replica_pid [srv 0 pid]
207
208 # make sure the master always fsyncs first (easier to test)
209 $master config set appendfsync always
210 $replica config set appendfsync no
211
212 test {WAITAOF on demoted master gets unblocked with an error} {
213 set rd [redis_deferring_client]
214 $rd incr foo
215 $rd read
216 $rd waitaof 0 1 0
217 wait_for_blocked_client
218 $replica replicaof $master_host $master_port
219 assert_error {UNBLOCKED force unblock from blocking operation,*} {$rd read}
220 $rd close
221 }
222
223 wait_for_ofs_sync $master $replica
224
225 test {WAITAOF replica copy before fsync} {
226 $master incr foo
227 assert_equal [$master waitaof 0 1 50] {1 0} ;# exits on timeout
228 }
229 $replica config set appendfsync everysec
230
231 test {WAITAOF replica copy everysec} {
232 $replica config set appendfsync everysec
233 waitForBgrewriteaof $replica ;# Make sure there is no AOFRW
234
235 $master incr foo
236 assert_equal [$master waitaof 0 1 0] {1 1}
237 }
238
239 test {WAITAOF replica copy everysec with AOFRW} {
240 $replica config set appendfsync everysec
241
242 # When we trigger an AOFRW, a fsync is triggered when closing the old INCR file,
243 # so with the everysec, we will skip that second of fsync, and in the next second
244 # after that, we will eventually do the fsync.
245 $replica bgrewriteaof
246 waitForBgrewriteaof $replica
247
248 $master incr foo
249 assert_equal [$master waitaof 0 1 0] {1 1}
250 }
251
252 test {WAITAOF replica copy everysec with slow AOFRW} {
253 $replica config set appendfsync everysec
254 $replica config set rdb-key-save-delay 1000000 ;# 1 sec
255
256 $replica bgrewriteaof
257
258 $master incr foo
259 assert_equal [$master waitaof 0 1 0] {1 1}
260
261 $replica config set rdb-key-save-delay 0
262 waitForBgrewriteaof $replica
263 }
264
265 test {WAITAOF replica copy everysec->always with AOFRW} {
266 $replica config set appendfsync everysec
267
268 # Try to fit all of them in the same round second, although there's no way to guarantee
269 # that, it can be done on fast machine. In any case, the test shouldn't fail either.
270 $replica bgrewriteaof
271 $master incr foo
272 waitForBgrewriteaof $replica
273 $replica config set appendfsync always
274
275 assert_equal [$master waitaof 0 1 0] {1 1}
276 }
277
278 test {WAITAOF replica copy appendfsync always} {
279 $replica config set appendfsync always
280 $master incr foo
281 assert_equal [$master waitaof 0 1 0] {1 1}
282 $replica config set appendfsync everysec
283 }
284
285 test {WAITAOF replica copy if replica is blocked} {
286 pause_process $replica_pid
287 $master incr foo
288 assert_equal [$master waitaof 0 1 50] {1 0} ;# exits on timeout
289 resume_process $replica_pid
290 assert_equal [$master waitaof 0 1 0] {1 1}
291 }
292
293 test {WAITAOF replica multiple clients unblock - reuse last result} {
294 set rd [redis_deferring_client -1]
295 set rd2 [redis_deferring_client -1]
296
297 pause_process $replica_pid
298
299 $rd incr foo
300 $rd read
301
302 $rd2 incr foo
303 $rd2 read
304
305 $rd waitaof 0 1 0
306 $rd2 waitaof 0 1 0
307 wait_for_blocked_clients_count 2 100 10 -1
308
309 resume_process $replica_pid
310
311 assert_equal [$rd read] {1 1}
312 assert_equal [$rd2 read] {1 1}
313
314 $rd ping
315 assert_equal [$rd read] {PONG}
316 $rd2 ping
317 assert_equal [$rd2 read] {PONG}
318
319 $rd close
320 $rd2 close
321 }
322
323 test {WAITAOF on promoted replica} {
324 $replica replicaof no one
325 $replica incr foo
326 assert_equal [$replica waitaof 1 0 0] {1 0}
327 }
328
329 test {WAITAOF master that loses a replica and backlog is dropped} {
330 $master config set repl-backlog-ttl 1
331 after 2000 ;# wait for backlog to expire
332 $master incr foo
333 assert_equal [$master waitaof 1 0 0] {1 0}
334 }
335
336 test {WAITAOF master without backlog, wait is released when the replica finishes full-sync} {
337 set rd [redis_deferring_client -1]
338 $rd incr foo
339 $rd read
340 $rd waitaof 0 1 0
341 wait_for_blocked_client -1
342 $replica replicaof $master_host $master_port
343 assert_equal [$rd read] {1 1}
344 $rd close
345 }
346
347 test {WAITAOF master isn't configured to do AOF} {
348 $master config set appendonly no
349 $master incr foo
350 assert_equal [$master waitaof 0 1 0] {0 1}
351 }
352
353 test {WAITAOF replica isn't configured to do AOF} {
354 $master config set appendonly yes
355 waitForBgrewriteaof $master
356 $replica config set appendonly no
357 $master incr foo
358 assert_equal [$master waitaof 1 0 0] {1 0}
359 }
360
361 test {WAITAOF both local and replica got AOF enabled at runtime} {
362 $replica config set appendonly yes
363 waitForBgrewriteaof $replica
364 $master incr foo
365 assert_equal [$master waitaof 1 1 0] {1 1}
366 }
367
368 test {WAITAOF master sends PING after last write} {
369 $master config set repl-ping-replica-period 1
370 $master incr foo
371 after 1200 ;# wait for PING
372 $master get foo
373 assert_equal [$master waitaof 1 1 0] {1 1}
374 $master config set repl-ping-replica-period 10
375 }
376
377 test {WAITAOF master client didn't send any write command} {
378 $master config set repl-ping-replica-period 1
379 set client [redis_client -1]
380 after 1200 ;# wait for PING
381 assert_equal [$master waitaof 1 1 0] {1 1}
382 $client close
383 $master config set repl-ping-replica-period 10
384 }
385
386 test {WAITAOF master client didn't send any command} {
387 $master config set repl-ping-replica-period 1
388 set client [redis [srv -1 "host"] [srv -1 "port"] 0 $::tls]
389 after 1200 ;# wait for PING
390 assert_equal [$master waitaof 1 1 0] {1 1}
391 $client close
392 $master config set repl-ping-replica-period 10
393 }
394
395 foreach fsync {no everysec always} {
396 test "WAITAOF when replica switches between masters, fsync: $fsync" {
397 # test a case where a replica is moved from one master to the other
398 # between two replication streams with different offsets that should
399 # not be mixed. done to smoke-test race conditions with bio thread.
400 start_server {overrides {appendonly {yes} auto-aof-rewrite-percentage {0}}} {
401 start_server {overrides {appendonly {yes} auto-aof-rewrite-percentage {0}}} {
402 set master2 [srv -1 client]
403 set master2_host [srv -1 host]
404 set master2_port [srv -1 port]
405 set replica2 [srv 0 client]
406 set replica2_host [srv 0 host]
407 set replica2_port [srv 0 port]
408 set replica2_pid [srv 0 pid]
409
410 $replica2 replicaof $master2_host $master2_port
411 wait_for_ofs_sync $master2 $replica2
412
413 $master config set appendfsync $fsync
414 $master2 config set appendfsync $fsync
415 $replica config set appendfsync $fsync
416 $replica2 config set appendfsync $fsync
417 if {$fsync eq "no"} {
418 after 2000 ;# wait for any previous fsync to finish
419 # can't afford "no" on the masters
420 $master config set appendfsync always
421 $master2 config set appendfsync always
422 } elseif {$fsync eq "everysec"} {
423 after 990 ;# hoping to hit a race
424 }
425
426 # add some writes and block a client on each master
427 set rd [redis_deferring_client -3]
428 set rd2 [redis_deferring_client -1]
429 $rd set boo 11
430 $rd2 set boo 22
431 $rd read
432 $rd2 read
433 $rd waitaof 1 1 0
434 $rd2 waitaof 1 1 0
435
436 if {$fsync eq "no"} {
437 # since appendfsync is disabled in the replicas, the client
438 # will get released only with full sync
439 wait_for_blocked_client -1
440 wait_for_blocked_client -3
441 }
442 # switch between the two replicas
443 $replica2 replicaof $master_host $master_port
444 $replica replicaof $master2_host $master2_port
445 assert_equal [$rd read] {1 1}
446 assert_equal [$rd2 read] {1 1}
447 $rd close
448 $rd2 close
449
450 assert_equal [$replica get boo] 22
451 assert_equal [$replica2 get boo] 11
452 }
453 }
454 }
455 }
456 }
457 }
458}
459
460start_server {tags {"failover external:skip"}} {
461start_server {} {
462start_server {} {
463 set master [srv 0 client]
464 set master_host [srv 0 host]
465 set master_port [srv 0 port]
466
467 set replica1 [srv -1 client]
468 set replica1_pid [srv -1 pid]
469
470 set replica2 [srv -2 client]
471
472 test {setup replication for following tests} {
473 $replica1 replicaof $master_host $master_port
474 $replica2 replicaof $master_host $master_port
475 wait_for_sync $replica1
476 wait_for_sync $replica2
477 }
478
479 test {WAIT and WAITAOF replica multiple clients unblock - reuse last result} {
480 set rd [redis_deferring_client]
481 set rd2 [redis_deferring_client]
482
483 $master config set appendonly yes
484 $replica1 config set appendonly yes
485 $replica2 config set appendonly yes
486
487 $master config set appendfsync always
488 $replica1 config set appendfsync no
489 $replica2 config set appendfsync no
490
491 waitForBgrewriteaof $master
492 waitForBgrewriteaof $replica1
493 waitForBgrewriteaof $replica2
494
495 pause_process $replica1_pid
496
497 $rd incr foo
498 $rd read
499 $rd waitaof 0 1 0
500
501 # rd2 has a newer repl_offset
502 $rd2 incr foo
503 $rd2 read
504 $rd2 wait 2 0
505
506 wait_for_blocked_clients_count 2
507
508 resume_process $replica1_pid
509
510 # WAIT will unblock the client first.
511 assert_equal [$rd2 read] {2}
512
513 # Make $replica1 catch up the repl_aof_off, then WAITAOF will unblock the client.
514 $replica1 config set appendfsync always
515 $master incr foo
516 assert_equal [$rd read] {1 1}
517
518 $rd ping
519 assert_equal [$rd read] {PONG}
520 $rd2 ping
521 assert_equal [$rd2 read] {PONG}
522
523 $rd close
524 $rd2 close
525 }
526}
527}
528}