diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
| commit | dcacc00e3750300617ba6e16eb346713f91a783a (patch) | |
| tree | 38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl | |
| parent | 58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff) | |
| download | crep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz | |
Remove testing data
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl')
| -rw-r--r-- | examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl | 437 |
1 files changed, 0 insertions, 437 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl b/examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl deleted file mode 100644 index d645de4..0000000 --- a/examples/redis-unstable/tests/unit/moduleapi/async_rm_call.tcl +++ /dev/null | |||
| @@ -1,437 +0,0 @@ | |||
| 1 | set testmodule [file normalize tests/modules/blockedclient.so] | ||
| 2 | set testmodule2 [file normalize tests/modules/postnotifications.so] | ||
| 3 | set testmodule3 [file normalize tests/modules/blockonkeys.so] | ||
| 4 | |||
| 5 | start_server {tags {"modules external:skip"}} { | ||
| 6 | r module load $testmodule | ||
| 7 | |||
| 8 | test {Locked GIL acquisition from async RM_Call} { | ||
| 9 | assert_equal {OK} [r do_rm_call_async acquire_gil] | ||
| 10 | } | ||
| 11 | |||
| 12 | test "Blpop on async RM_Call fire and forget" { | ||
| 13 | assert_equal {Blocked} [r do_rm_call_fire_and_forget blpop l 0] | ||
| 14 | r lpush l a | ||
| 15 | assert_equal {0} [r llen l] | ||
| 16 | } | ||
| 17 | |||
| 18 | test "Blpop on threaded async RM_Call" { | ||
| 19 | set rd [redis_deferring_client] | ||
| 20 | |||
| 21 | $rd do_rm_call_async_on_thread blpop l 0 | ||
| 22 | wait_for_blocked_clients_count 1 | ||
| 23 | r lpush l a | ||
| 24 | assert_equal [$rd read] {l a} | ||
| 25 | wait_for_blocked_clients_count 0 | ||
| 26 | $rd close | ||
| 27 | } | ||
| 28 | |||
| 29 | foreach cmd {do_rm_call_async do_rm_call_async_script_mode } { | ||
| 30 | |||
| 31 | test "Blpop on async RM_Call using $cmd" { | ||
| 32 | set rd [redis_deferring_client] | ||
| 33 | |||
| 34 | $rd $cmd blpop l 0 | ||
| 35 | wait_for_blocked_clients_count 1 | ||
| 36 | r lpush l a | ||
| 37 | assert_equal [$rd read] {l a} | ||
| 38 | wait_for_blocked_clients_count 0 | ||
| 39 | $rd close | ||
| 40 | } | ||
| 41 | |||
| 42 | test "Brpop on async RM_Call using $cmd" { | ||
| 43 | set rd [redis_deferring_client] | ||
| 44 | |||
| 45 | $rd $cmd brpop l 0 | ||
| 46 | wait_for_blocked_clients_count 1 | ||
| 47 | r lpush l a | ||
| 48 | assert_equal [$rd read] {l a} | ||
| 49 | wait_for_blocked_clients_count 0 | ||
| 50 | $rd close | ||
| 51 | } | ||
| 52 | |||
| 53 | test "Brpoplpush on async RM_Call using $cmd" { | ||
| 54 | set rd [redis_deferring_client] | ||
| 55 | |||
| 56 | $rd $cmd brpoplpush l1 l2 0 | ||
| 57 | wait_for_blocked_clients_count 1 | ||
| 58 | r lpush l1 a | ||
| 59 | assert_equal [$rd read] {a} | ||
| 60 | wait_for_blocked_clients_count 0 | ||
| 61 | $rd close | ||
| 62 | r lpop l2 | ||
| 63 | } {a} | ||
| 64 | |||
| 65 | test "Blmove on async RM_Call using $cmd" { | ||
| 66 | set rd [redis_deferring_client] | ||
| 67 | |||
| 68 | $rd $cmd blmove l1 l2 LEFT LEFT 0 | ||
| 69 | wait_for_blocked_clients_count 1 | ||
| 70 | r lpush l1 a | ||
| 71 | assert_equal [$rd read] {a} | ||
| 72 | wait_for_blocked_clients_count 0 | ||
| 73 | $rd close | ||
| 74 | r lpop l2 | ||
| 75 | } {a} | ||
| 76 | |||
| 77 | test "Bzpopmin on async RM_Call using $cmd" { | ||
| 78 | set rd [redis_deferring_client] | ||
| 79 | |||
| 80 | $rd $cmd bzpopmin s 0 | ||
| 81 | wait_for_blocked_clients_count 1 | ||
| 82 | r zadd s 10 foo | ||
| 83 | assert_equal [$rd read] {s foo 10} | ||
| 84 | wait_for_blocked_clients_count 0 | ||
| 85 | $rd close | ||
| 86 | } | ||
| 87 | |||
| 88 | test "Bzpopmax on async RM_Call using $cmd" { | ||
| 89 | set rd [redis_deferring_client] | ||
| 90 | |||
| 91 | $rd $cmd bzpopmax s 0 | ||
| 92 | wait_for_blocked_clients_count 1 | ||
| 93 | r zadd s 10 foo | ||
| 94 | assert_equal [$rd read] {s foo 10} | ||
| 95 | wait_for_blocked_clients_count 0 | ||
| 96 | $rd close | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | test {Nested async RM_Call} { | ||
| 101 | set rd [redis_deferring_client] | ||
| 102 | |||
| 103 | $rd do_rm_call_async do_rm_call_async do_rm_call_async do_rm_call_async blpop l 0 | ||
| 104 | wait_for_blocked_clients_count 1 | ||
| 105 | r lpush l a | ||
| 106 | assert_equal [$rd read] {l a} | ||
| 107 | wait_for_blocked_clients_count 0 | ||
| 108 | $rd close | ||
| 109 | } | ||
| 110 | |||
| 111 | test {Test multiple async RM_Call waiting on the same event} { | ||
| 112 | set rd1 [redis_deferring_client] | ||
| 113 | set rd2 [redis_deferring_client] | ||
| 114 | |||
| 115 | $rd1 do_rm_call_async do_rm_call_async do_rm_call_async do_rm_call_async blpop l 0 | ||
| 116 | $rd2 do_rm_call_async do_rm_call_async do_rm_call_async do_rm_call_async blpop l 0 | ||
| 117 | wait_for_blocked_clients_count 2 | ||
| 118 | r lpush l element element | ||
| 119 | assert_equal [$rd1 read] {l element} | ||
| 120 | assert_equal [$rd2 read] {l element} | ||
| 121 | wait_for_blocked_clients_count 0 | ||
| 122 | $rd1 close | ||
| 123 | $rd2 close | ||
| 124 | } | ||
| 125 | |||
| 126 | test {async RM_Call calls RM_Call} { | ||
| 127 | assert_equal {PONG} [r do_rm_call_async do_rm_call ping] | ||
| 128 | } | ||
| 129 | |||
| 130 | test {async RM_Call calls background RM_Call calls RM_Call} { | ||
| 131 | assert_equal {PONG} [r do_rm_call_async do_bg_rm_call do_rm_call ping] | ||
| 132 | } | ||
| 133 | |||
| 134 | test {async RM_Call calls background RM_Call calls RM_Call calls async RM_Call} { | ||
| 135 | assert_equal {PONG} [r do_rm_call_async do_bg_rm_call do_rm_call do_rm_call_async ping] | ||
| 136 | } | ||
| 137 | |||
| 138 | test {async RM_Call inside async RM_Call callback} { | ||
| 139 | set rd [redis_deferring_client] | ||
| 140 | $rd wait_and_do_rm_call blpop l 0 | ||
| 141 | wait_for_blocked_clients_count 1 | ||
| 142 | |||
| 143 | start_server {} { | ||
| 144 | test "Connect a replica to the master instance" { | ||
| 145 | r slaveof [srv -1 host] [srv -1 port] | ||
| 146 | wait_for_condition 50 100 { | ||
| 147 | [s role] eq {slave} && | ||
| 148 | [string match {*master_link_status:up*} [r info replication]] | ||
| 149 | } else { | ||
| 150 | fail "Can't turn the instance into a replica" | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | assert_equal {1} [r -1 lpush l a] | ||
| 155 | assert_equal [$rd read] {l a} | ||
| 156 | } | ||
| 157 | |||
| 158 | wait_for_blocked_clients_count 0 | ||
| 159 | $rd close | ||
| 160 | } | ||
| 161 | |||
| 162 | test {Become replica while having async RM_Call running} { | ||
| 163 | r flushall | ||
| 164 | set rd [redis_deferring_client] | ||
| 165 | $rd do_rm_call_async blpop l 0 | ||
| 166 | wait_for_blocked_clients_count 1 | ||
| 167 | |||
| 168 | #become a replica of a not existing redis | ||
| 169 | r replicaof localhost 30000 | ||
| 170 | |||
| 171 | catch {[$rd read]} e | ||
| 172 | assert_match {UNBLOCKED force unblock from blocking operation*} $e | ||
| 173 | wait_for_blocked_clients_count 0 | ||
| 174 | |||
| 175 | r replicaof no one | ||
| 176 | |||
| 177 | r lpush l 1 | ||
| 178 | # make sure the async rm_call was aborted | ||
| 179 | assert_equal [r llen l] {1} | ||
| 180 | $rd close | ||
| 181 | } | ||
| 182 | |||
| 183 | test {Pipeline with blocking RM_Call} { | ||
| 184 | r flushall | ||
| 185 | set rd [redis_deferring_client] | ||
| 186 | set buf "" | ||
| 187 | append buf "do_rm_call_async blpop l 0\r\n" | ||
| 188 | append buf "ping\r\n" | ||
| 189 | $rd write $buf | ||
| 190 | $rd flush | ||
| 191 | wait_for_blocked_clients_count 1 | ||
| 192 | |||
| 193 | # release the blocked client | ||
| 194 | r lpush l 1 | ||
| 195 | |||
| 196 | assert_equal [$rd read] {l 1} | ||
| 197 | assert_equal [$rd read] {PONG} | ||
| 198 | |||
| 199 | wait_for_blocked_clients_count 0 | ||
| 200 | $rd close | ||
| 201 | } | ||
| 202 | |||
| 203 | test {blocking RM_Call abort} { | ||
| 204 | r flushall | ||
| 205 | set rd [redis_deferring_client] | ||
| 206 | |||
| 207 | $rd client id | ||
| 208 | set client_id [$rd read] | ||
| 209 | |||
| 210 | $rd do_rm_call_async blpop l 0 | ||
| 211 | wait_for_blocked_clients_count 1 | ||
| 212 | |||
| 213 | r client kill ID $client_id | ||
| 214 | assert_error {*error reading reply*} {$rd read} | ||
| 215 | |||
| 216 | wait_for_blocked_clients_count 0 | ||
| 217 | |||
| 218 | r lpush l 1 | ||
| 219 | # make sure the async rm_call was aborted | ||
| 220 | assert_equal [r llen l] {1} | ||
| 221 | $rd close | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | start_server {tags {"modules external:skip"}} { | ||
| 226 | r module load $testmodule | ||
| 227 | |||
| 228 | test {Test basic replication stream on unblock handler} { | ||
| 229 | r flushall | ||
| 230 | set repl [attach_to_replication_stream] | ||
| 231 | |||
| 232 | set rd [redis_deferring_client] | ||
| 233 | |||
| 234 | $rd do_rm_call_async blpop l 0 | ||
| 235 | wait_for_blocked_clients_count 1 | ||
| 236 | r lpush l a | ||
| 237 | assert_equal [$rd read] {l a} | ||
| 238 | |||
| 239 | assert_replication_stream $repl { | ||
| 240 | {select *} | ||
| 241 | {lpush l a} | ||
| 242 | {lpop l} | ||
| 243 | } | ||
| 244 | close_replication_stream $repl | ||
| 245 | |||
| 246 | wait_for_blocked_clients_count 0 | ||
| 247 | $rd close | ||
| 248 | } | ||
| 249 | |||
| 250 | test {Test unblock handler are executed as a unit} { | ||
| 251 | r flushall | ||
| 252 | set repl [attach_to_replication_stream] | ||
| 253 | |||
| 254 | set rd [redis_deferring_client] | ||
| 255 | |||
| 256 | $rd blpop_and_set_multiple_keys l x 1 y 2 | ||
| 257 | wait_for_blocked_clients_count 1 | ||
| 258 | r lpush l a | ||
| 259 | assert_equal [$rd read] {OK} | ||
| 260 | |||
| 261 | assert_replication_stream $repl { | ||
| 262 | {select *} | ||
| 263 | {lpush l a} | ||
| 264 | {multi} | ||
| 265 | {lpop l} | ||
| 266 | {set x 1} | ||
| 267 | {set y 2} | ||
| 268 | {exec} | ||
| 269 | } | ||
| 270 | close_replication_stream $repl | ||
| 271 | |||
| 272 | wait_for_blocked_clients_count 0 | ||
| 273 | $rd close | ||
| 274 | } | ||
| 275 | |||
| 276 | test {Test no propagation of blocking command} { | ||
| 277 | r flushall | ||
| 278 | set repl [attach_to_replication_stream] | ||
| 279 | |||
| 280 | set rd [redis_deferring_client] | ||
| 281 | |||
| 282 | $rd do_rm_call_async_no_replicate blpop l 0 | ||
| 283 | wait_for_blocked_clients_count 1 | ||
| 284 | r lpush l a | ||
| 285 | assert_equal [$rd read] {l a} | ||
| 286 | |||
| 287 | # make sure the lpop are not replicated | ||
| 288 | r set x 1 | ||
| 289 | |||
| 290 | assert_replication_stream $repl { | ||
| 291 | {select *} | ||
| 292 | {lpush l a} | ||
| 293 | {set x 1} | ||
| 294 | } | ||
| 295 | close_replication_stream $repl | ||
| 296 | |||
| 297 | wait_for_blocked_clients_count 0 | ||
| 298 | $rd close | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | start_server {tags {"modules external:skip"}} { | ||
| 303 | r module load $testmodule | ||
| 304 | r module load $testmodule2 | ||
| 305 | |||
| 306 | test {Test unblock handler are executed as a unit with key space notifications} { | ||
| 307 | r flushall | ||
| 308 | set repl [attach_to_replication_stream] | ||
| 309 | |||
| 310 | set rd [redis_deferring_client] | ||
| 311 | |||
| 312 | $rd blpop_and_set_multiple_keys l string_foo 1 string_bar 2 | ||
| 313 | wait_for_blocked_clients_count 1 | ||
| 314 | r lpush l a | ||
| 315 | assert_equal [$rd read] {OK} | ||
| 316 | |||
| 317 | # Explanation of the first multi exec block: | ||
| 318 | # {lpop l} - pop the value by our blocking command 'blpop_and_set_multiple_keys' | ||
| 319 | # {set string_foo 1} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 320 | # {set string_bar 2} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 321 | # {incr string_changed{string_foo}} - post notification job that was registered when 'string_foo' changed | ||
| 322 | # {incr string_changed{string_bar}} - post notification job that was registered when 'string_bar' changed | ||
| 323 | # {incr string_total} - post notification job that was registered when string_changed{string_foo} changed | ||
| 324 | # {incr string_total} - post notification job that was registered when string_changed{string_bar} changed | ||
| 325 | assert_replication_stream $repl { | ||
| 326 | {select *} | ||
| 327 | {lpush l a} | ||
| 328 | {multi} | ||
| 329 | {lpop l} | ||
| 330 | {set string_foo 1} | ||
| 331 | {set string_bar 2} | ||
| 332 | {incr string_changed{string_foo}} | ||
| 333 | {incr string_changed{string_bar}} | ||
| 334 | {incr string_total} | ||
| 335 | {incr string_total} | ||
| 336 | {exec} | ||
| 337 | } | ||
| 338 | close_replication_stream $repl | ||
| 339 | |||
| 340 | wait_for_blocked_clients_count 0 | ||
| 341 | $rd close | ||
| 342 | } | ||
| 343 | |||
| 344 | test {Test unblock handler are executed as a unit with lazy expire} { | ||
| 345 | r flushall | ||
| 346 | r DEBUG SET-ACTIVE-EXPIRE 0 | ||
| 347 | set repl [attach_to_replication_stream] | ||
| 348 | |||
| 349 | set rd [redis_deferring_client] | ||
| 350 | |||
| 351 | $rd blpop_and_set_multiple_keys l string_foo 1 string_bar 2 | ||
| 352 | wait_for_blocked_clients_count 1 | ||
| 353 | r lpush l a | ||
| 354 | assert_equal [$rd read] {OK} | ||
| 355 | |||
| 356 | # set expiration on string_foo | ||
| 357 | r pexpire string_foo 1 | ||
| 358 | after 10 | ||
| 359 | |||
| 360 | # now the key should have been expired | ||
| 361 | $rd blpop_and_set_multiple_keys l string_foo 1 string_bar 2 | ||
| 362 | wait_for_blocked_clients_count 1 | ||
| 363 | r lpush l a | ||
| 364 | assert_equal [$rd read] {OK} | ||
| 365 | |||
| 366 | # Explanation of the first multi exec block: | ||
| 367 | # {lpop l} - pop the value by our blocking command 'blpop_and_set_multiple_keys' | ||
| 368 | # {set string_foo 1} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 369 | # {set string_bar 2} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 370 | # {incr string_changed{string_foo}} - post notification job that was registered when 'string_foo' changed | ||
| 371 | # {incr string_changed{string_bar}} - post notification job that was registered when 'string_bar' changed | ||
| 372 | # {incr string_total} - post notification job that was registered when string_changed{string_foo} changed | ||
| 373 | # {incr string_total} - post notification job that was registered when string_changed{string_bar} changed | ||
| 374 | # | ||
| 375 | # Explanation of the second multi exec block: | ||
| 376 | # {lpop l} - pop the value by our blocking command 'blpop_and_set_multiple_keys' | ||
| 377 | # {del string_foo} - lazy expiration of string_foo when 'blpop_and_set_multiple_keys' tries to write to it. | ||
| 378 | # {set string_foo 1} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 379 | # {set string_bar 2} - the action of our blocking command 'blpop_and_set_multiple_keys' | ||
| 380 | # {incr expired} - the post notification job, registered after string_foo got expired | ||
| 381 | # {incr string_changed{string_foo}} - post notification job triggered when we set string_foo | ||
| 382 | # {incr string_changed{string_bar}} - post notification job triggered when we set string_bar | ||
| 383 | # {incr string_total} - post notification job triggered when we incr 'string_changed{string_foo}' | ||
| 384 | # {incr string_total} - post notification job triggered when we incr 'string_changed{string_bar}' | ||
| 385 | assert_replication_stream $repl { | ||
| 386 | {select *} | ||
| 387 | {lpush l a} | ||
| 388 | {multi} | ||
| 389 | {lpop l} | ||
| 390 | {set string_foo 1} | ||
| 391 | {set string_bar 2} | ||
| 392 | {incr string_changed{string_foo}} | ||
| 393 | {incr string_changed{string_bar}} | ||
| 394 | {incr string_total} | ||
| 395 | {incr string_total} | ||
| 396 | {exec} | ||
| 397 | {pexpireat string_foo *} | ||
| 398 | {lpush l a} | ||
| 399 | {multi} | ||
| 400 | {lpop l} | ||
| 401 | {del string_foo} | ||
| 402 | {set string_foo 1} | ||
| 403 | {set string_bar 2} | ||
| 404 | {incr expired} | ||
| 405 | {incr string_changed{string_foo}} | ||
| 406 | {incr string_changed{string_bar}} | ||
| 407 | {incr string_total} | ||
| 408 | {incr string_total} | ||
| 409 | {exec} | ||
| 410 | } | ||
| 411 | close_replication_stream $repl | ||
| 412 | r DEBUG SET-ACTIVE-EXPIRE 1 | ||
| 413 | |||
| 414 | wait_for_blocked_clients_count 0 | ||
| 415 | $rd close | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | start_server {tags {"modules external:skip"}} { | ||
| 420 | r module load $testmodule | ||
| 421 | r module load $testmodule3 | ||
| 422 | |||
| 423 | test {Test unblock handler on module blocked on keys} { | ||
| 424 | set rd [redis_deferring_client] | ||
| 425 | |||
| 426 | r fsl.push l 1 | ||
| 427 | $rd do_rm_call_async FSL.BPOPGT l 3 0 | ||
| 428 | wait_for_blocked_clients_count 1 | ||
| 429 | r fsl.push l 2 | ||
| 430 | r fsl.push l 3 | ||
| 431 | r fsl.push l 4 | ||
| 432 | assert_equal [$rd read] {4} | ||
| 433 | |||
| 434 | wait_for_blocked_clients_count 0 | ||
| 435 | $rd close | ||
| 436 | } | ||
| 437 | } | ||
