aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/moduleapi/blockonkeys.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/moduleapi/blockonkeys.tcl
parent58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff)
downloadcrep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz
Remove testing data
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/blockonkeys.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/moduleapi/blockonkeys.tcl366
1 files changed, 0 insertions, 366 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/blockonkeys.tcl b/examples/redis-unstable/tests/unit/moduleapi/blockonkeys.tcl
deleted file mode 100644
index 53aee73..0000000
--- a/examples/redis-unstable/tests/unit/moduleapi/blockonkeys.tcl
+++ /dev/null
@@ -1,366 +0,0 @@
1set testmodule [file normalize tests/modules/blockonkeys.so]
2
3start_server {tags {"modules external:skip"}} {
4 r module load $testmodule
5
6 test "Module client blocked on keys: Circular BPOPPUSH" {
7 set rd1 [redis_deferring_client]
8 set rd2 [redis_deferring_client]
9
10 r del src dst
11
12 $rd1 fsl.bpoppush src dst 0
13 wait_for_blocked_clients_count 1
14
15 $rd2 fsl.bpoppush dst src 0
16 wait_for_blocked_clients_count 2
17
18 r fsl.push src 42
19 wait_for_blocked_clients_count 0
20
21 assert_equal {42} [r fsl.getall src]
22 assert_equal {} [r fsl.getall dst]
23 }
24
25 test "Module client blocked on keys: Self-referential BPOPPUSH" {
26 set rd1 [redis_deferring_client]
27
28 r del src
29
30 $rd1 fsl.bpoppush src src 0
31 wait_for_blocked_clients_count 1
32 r fsl.push src 42
33
34 assert_equal {42} [r fsl.getall src]
35 }
36
37 test "Module client blocked on keys: BPOPPUSH unblocked by timer" {
38 set rd1 [redis_deferring_client]
39
40 r del src dst
41
42 set repl [attach_to_replication_stream]
43
44 $rd1 fsl.bpoppush src dst 0
45 wait_for_blocked_clients_count 1
46
47 r fsl.pushtimer src 9000 10
48 wait_for_blocked_clients_count 0
49
50 assert_equal {9000} [r fsl.getall dst]
51 assert_equal {} [r fsl.getall src]
52
53 assert_replication_stream $repl {
54 {select *}
55 {fsl.push src 9000}
56 {fsl.bpoppush src dst 0}
57 }
58
59 close_replication_stream $repl
60 } {} {needs:repl}
61
62 test {Module client blocked on keys (no metadata): No block} {
63 r del k
64 r fsl.push k 33
65 r fsl.push k 34
66 r fsl.bpop k 0
67 } {34}
68
69 test {Module client blocked on keys (no metadata): Timeout} {
70 r del k
71 set rd [redis_deferring_client]
72 $rd fsl.bpop k 1
73 assert_equal {Request timedout} [$rd read]
74 }
75
76 test {Module client blocked on keys (no metadata): Blocked} {
77 r del k
78 set rd [redis_deferring_client]
79 $rd fsl.bpop k 0
80 wait_for_blocked_clients_count 1
81 r fsl.push k 34
82 assert_equal {34} [$rd read]
83 }
84
85 test {Module client blocked on keys (with metadata): No block} {
86 r del k
87 r fsl.push k 34
88 r fsl.bpopgt k 30 0
89 } {34}
90
91 test {Module client blocked on keys (with metadata): Timeout} {
92 r del k
93 set rd [redis_deferring_client]
94 $rd client id
95 set cid [$rd read]
96 r fsl.push k 33
97 $rd fsl.bpopgt k 35 1
98 assert_equal {Request timedout} [$rd read]
99 r client kill id $cid ;# try to smoke-out client-related memory leak
100 }
101
102 test {Module client blocked on keys (with metadata): Blocked, case 1} {
103 r del k
104 set rd [redis_deferring_client]
105 $rd client id
106 set cid [$rd read]
107 r fsl.push k 33
108 $rd fsl.bpopgt k 33 0
109 wait_for_blocked_clients_count 1
110 r fsl.push k 34
111 assert_equal {34} [$rd read]
112 r client kill id $cid ;# try to smoke-out client-related memory leak
113 }
114
115 test {Module client blocked on keys (with metadata): Blocked, case 2} {
116 r del k
117 r fsl.push k 32
118 set rd [redis_deferring_client]
119 $rd fsl.bpopgt k 35 0
120 wait_for_blocked_clients_count 1
121 r fsl.push k 33
122 r fsl.push k 34
123 r fsl.push k 35
124 r fsl.push k 36
125 assert_equal {36} [$rd read]
126 }
127
128 test {Module client blocked on keys (with metadata): Blocked, DEL} {
129 r del k
130 r fsl.push k 32
131 set rd [redis_deferring_client]
132 $rd fsl.bpopgt k 35 0
133 wait_for_blocked_clients_count 1
134 r del k
135 assert_error {*UNBLOCKED key no longer exists*} {$rd read}
136 }
137
138 test {Module client blocked on keys (with metadata): Blocked, FLUSHALL} {
139 r del k
140 r fsl.push k 32
141 set rd [redis_deferring_client]
142 $rd fsl.bpopgt k 35 0
143 wait_for_blocked_clients_count 1
144 r flushall
145 assert_error {*UNBLOCKED key no longer exists*} {$rd read}
146 }
147
148 test {Module client blocked on keys (with metadata): Blocked, SWAPDB, no key} {
149 r select 9
150 r del k
151 r fsl.push k 32
152 set rd [redis_deferring_client]
153 $rd fsl.bpopgt k 35 0
154 wait_for_blocked_clients_count 1
155 r swapdb 0 9
156 assert_error {*UNBLOCKED key no longer exists*} {$rd read}
157 }
158
159 test {Module client blocked on keys (with metadata): Blocked, SWAPDB, key exists, case 1} {
160 ;# Key exists on other db, but wrong type
161 r flushall
162 r select 9
163 r fsl.push k 32
164 r select 0
165 r lpush k 38
166 r select 9
167 set rd [redis_deferring_client]
168 $rd fsl.bpopgt k 35 0
169 wait_for_blocked_clients_count 1
170 r swapdb 0 9
171 assert_error {*UNBLOCKED key no longer exists*} {$rd read}
172 r select 9
173 }
174
175 test {Module client blocked on keys (with metadata): Blocked, SWAPDB, key exists, case 2} {
176 ;# Key exists on other db, with the right type, but the value doesn't allow to unblock
177 r flushall
178 r select 9
179 r fsl.push k 32
180 r select 0
181 r fsl.push k 34
182 r select 9
183 set rd [redis_deferring_client]
184 $rd fsl.bpopgt k 35 0
185 wait_for_blocked_clients_count 1
186 r swapdb 0 9
187 assert_equal {1} [s 0 blocked_clients]
188 r fsl.push k 38
189 assert_equal {38} [$rd read]
190 r select 9
191 }
192
193 test {Module client blocked on keys (with metadata): Blocked, SWAPDB, key exists, case 3} {
194 ;# Key exists on other db, with the right type, the value allows to unblock
195 r flushall
196 r select 9
197 r fsl.push k 32
198 r select 0
199 r fsl.push k 38
200 r select 9
201 set rd [redis_deferring_client]
202 $rd fsl.bpopgt k 35 0
203 wait_for_blocked_clients_count 1
204 r swapdb 0 9
205 assert_equal {38} [$rd read]
206 r select 9
207 }
208
209 test {Module client blocked on keys (with metadata): Blocked, CLIENT KILL} {
210 r del k
211 r fsl.push k 32
212 set rd [redis_deferring_client]
213 $rd client id
214 set cid [$rd read]
215 $rd fsl.bpopgt k 35 0
216 wait_for_blocked_clients_count 1
217 r client kill id $cid ;# try to smoke-out client-related memory leak
218 }
219
220 test {Module client blocked on keys (with metadata): Blocked, CLIENT UNBLOCK TIMEOUT} {
221 r del k
222 r fsl.push k 32
223 set rd [redis_deferring_client]
224 $rd client id
225 set cid [$rd read]
226 $rd fsl.bpopgt k 35 0
227 wait_for_blocked_clients_count 1
228 r client unblock $cid timeout ;# try to smoke-out client-related memory leak
229 assert_equal {Request timedout} [$rd read]
230 }
231
232 test {Module client blocked on keys (with metadata): Blocked, CLIENT UNBLOCK ERROR} {
233 r del k
234 r fsl.push k 32
235 set rd [redis_deferring_client]
236 $rd client id
237 set cid [$rd read]
238 $rd fsl.bpopgt k 35 0
239 wait_for_blocked_clients_count 1
240 r client unblock $cid error ;# try to smoke-out client-related memory leak
241 assert_error "*unblocked*" {$rd read}
242 }
243
244 test {Module client blocked on keys, no timeout CB, CLIENT UNBLOCK TIMEOUT} {
245 r del k
246 set rd [redis_deferring_client]
247 $rd client id
248 set cid [$rd read]
249 $rd fsl.bpop k 0 NO_TO_CB
250 wait_for_blocked_clients_count 1
251 assert_equal [r client unblock $cid timeout] {0}
252 $rd close
253 }
254
255 test {Module client blocked on keys, no timeout CB, CLIENT UNBLOCK ERROR} {
256 r del k
257 set rd [redis_deferring_client]
258 $rd client id
259 set cid [$rd read]
260 $rd fsl.bpop k 0 NO_TO_CB
261 wait_for_blocked_clients_count 1
262 assert_equal [r client unblock $cid error] {0}
263 $rd close
264 }
265
266 test {Module client re-blocked on keys after woke up on wrong type} {
267 r del k
268 set rd [redis_deferring_client]
269 $rd fsl.bpop k 0
270 wait_for_blocked_clients_count 1
271 r lpush k 12
272 r lpush k 13
273 r lpush k 14
274 r del k
275 r fsl.push k 34
276 assert_equal {34} [$rd read]
277 assert_equal {1} [r get fsl_wrong_type] ;# first lpush caused one wrong-type wake-up
278 }
279
280 test {Module client blocked on keys woken up by LPUSH} {
281 r del k
282 set rd [redis_deferring_client]
283 $rd blockonkeys.popall k
284 wait_for_blocked_clients_count 1
285 r lpush k 42 squirrel banana
286 assert_equal {banana squirrel 42} [$rd read]
287 $rd close
288 }
289
290 test {Module client unblocks BLPOP} {
291 r del k
292 set rd [redis_deferring_client]
293 $rd blpop k 3
294 wait_for_blocked_clients_count 1
295 r blockonkeys.lpush k 42
296 assert_equal {k 42} [$rd read]
297 $rd close
298 }
299
300 test {Module unblocks module blocked on non-empty list} {
301 r del k
302 r lpush k aa
303 # Module client blocks to pop 5 elements from list
304 set rd [redis_deferring_client]
305 $rd blockonkeys.blpopn k 5
306 wait_for_blocked_clients_count 1
307 # Check that RM_SignalKeyAsReady() can wake up BLPOPN
308 r blockonkeys.lpush_unblock k bb cc ;# Not enough elements for BLPOPN
309 r lpush k dd ee ff ;# Doesn't unblock module
310 r blockonkeys.lpush_unblock k gg ;# Unblocks module
311 assert_equal {gg ff ee dd cc} [$rd read]
312 $rd close
313 }
314
315 test {Module explicit unblock when blocked on keys} {
316 r del k
317 r set somekey someval
318 # Module client blocks to pop 5 elements from list
319 set rd [redis_deferring_client]
320 $rd blockonkeys.blpopn_or_unblock k 5 0
321 wait_for_blocked_clients_count 1
322 # will now cause the module to trigger pop but instead will unblock the client from the reply_callback
323 r lpush k dd
324 # we should still get unblocked as the command should not reprocess
325 wait_for_blocked_clients_count 0
326 assert_equal {Action aborted} [$rd read]
327 $rd get somekey
328 assert_equal {someval} [$rd read]
329 $rd close
330 }
331
332 set master [srv 0 client]
333 set master_host [srv 0 host]
334 set master_port [srv 0 port]
335 start_server [list overrides [list loadmodule "$testmodule"] tags {"external:skip"}] {
336 set replica [srv 0 client]
337 set replica_host [srv 0 host]
338 set replica_port [srv 0 port]
339
340 # Start the replication process...
341 $replica replicaof $master_host $master_port
342 wait_for_sync $replica
343
344 test {WAIT command on module blocked client on keys} {
345 set rd [redis_deferring_client -1]
346 $rd set x y
347 $rd read
348
349 pause_process [srv 0 pid]
350
351 $master del k
352 $rd fsl.bpop k 0
353 wait_for_blocked_client -1
354 $master fsl.push k 34
355 $master fsl.push k 35
356 assert_equal {34} [$rd read]
357
358 assert_equal [$master wait 1 1000] 0
359 resume_process [srv 0 pid]
360 assert_equal [$master wait 1 1000] 1
361 $rd close
362 assert_equal {35} [$replica fsl.getall k]
363 }
364 }
365
366}