diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/expire.tcl | 23 | ||||
-rw-r--r-- | tests/unit/maxmemory.tcl | 2 | ||||
-rw-r--r-- | tests/unit/moduleapi/propagate.tcl | 192 | ||||
-rw-r--r-- | tests/unit/multi.tcl | 6 |
4 files changed, 165 insertions, 58 deletions
diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index d85d59e7a..8e4954a34 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -745,4 +745,27 @@ start_server {tags {"expire"}} { assert_equal [r EXPIRE none 100 GT] 0 assert_equal [r EXPIRE none 100 LT] 0 } {} + + test {Redis should not propagate the read command on lazy expire} { + r debug set-active-expire 0 + r flushall ; # Clean up keyspace to avoid interference by keys from other tests + r set foo bar PX 1 + set repl [attach_to_replication_stream] + wait_for_condition 50 100 { + [r get foo] eq {} + } else { + fail "Replication not started." + } + + # dummy command to verify nothing else gets into the replication stream. + r set x 1 + + assert_replication_stream $repl { + {select *} + {del foo} + {set x 1} + } + close_replication_stream $repl + assert_equal [r debug set-active-expire 1] {OK} + } {} {needs:debug} } diff --git a/tests/unit/maxmemory.tcl b/tests/unit/maxmemory.tcl index 8b0e5045a..631b3ac91 100644 --- a/tests/unit/maxmemory.tcl +++ b/tests/unit/maxmemory.tcl @@ -558,8 +558,8 @@ start_server {tags {"maxmemory" "external:skip"}} { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incr x} {incr x} {exec} diff --git a/tests/unit/moduleapi/propagate.tcl b/tests/unit/moduleapi/propagate.tcl index 846d938fb..39189b715 100644 --- a/tests/unit/moduleapi/propagate.tcl +++ b/tests/unit/moduleapi/propagate.tcl @@ -45,10 +45,10 @@ tags "modules" { $master set x y assert_replication_stream $repl { - {select *} {multi} - {incr notifications} + {select *} {set x y} + {incr notifications} {exec} } close_replication_stream $repl @@ -63,12 +63,12 @@ tags "modules" { $master exec assert_replication_stream $repl { - {select *} {multi} - {incr notifications} + {select *} {set x1 y1} {incr notifications} {set x2 y2} + {incr notifications} {exec} } close_replication_stream $repl @@ -91,34 +91,40 @@ tags "modules" { # Note whenever there's double notification: SET with PX issues two separate # notifications: one for "set" and one for "expire" assert_replication_stream $repl { - {select *} {multi} + {select *} + {set asdf1 1 PXAT *} {incr notifications} {incr notifications} - {set asdf1 1 PXAT *} {exec} {multi} + {set asdf2 2 PXAT *} {incr notifications} {incr notifications} - {set asdf2 2 PXAT *} {exec} {multi} + {set asdf3 3 PXAT *} {incr notifications} {incr notifications} - {set asdf3 3 PXAT *} {exec} - {incr notifications} + {multi} + {del asdf*} {incr notifications} {incr testkeyspace:expired} - {del asdf*} {incr notifications} + {exec} + {multi} + {del asdf*} {incr notifications} {incr testkeyspace:expired} - {del asdf*} {incr notifications} + {exec} + {multi} + {del asdf*} {incr notifications} {incr testkeyspace:expired} - {del asdf*} + {incr notifications} + {exec} } close_replication_stream $repl @@ -143,8 +149,11 @@ tags "modules" { # Bottom line: "notifications" always exists and we can't really determine the order of evictions # This test is here only for sanity + # The replica will get the notification with multi exec and we have a generic notification handler + # that performs `RedisModule_Call(ctx, "INCR", "c", "multi");` if the notification is inside multi exec. + # so we will have 2 keys, "notifications" and "multi". wait_for_condition 500 10 { - [$replica dbsize] eq 1 + [$replica dbsize] eq 2 } else { fail "Not all keys have been evicted" } @@ -183,31 +192,37 @@ tags "modules" { # Note that although CONFIG SET maxmemory is called in this flow (see issue #10014), # eviction will happen and will not induce propagation of the CONFIG command (see #10019). assert_replication_stream $repl { - {select *} {multi} + {select *} + {set asdf1 1 PXAT *} {incr notifications} {incr notifications} - {set asdf1 1 PXAT *} {exec} {multi} + {set asdf2 2 PXAT *} {incr notifications} {incr notifications} - {set asdf2 2 PXAT *} {exec} {multi} + {set asdf3 3 PXAT *} {incr notifications} {incr notifications} - {set asdf3 3 PXAT *} {exec} - {incr notifications} + {multi} {del asdf*} {incr notifications} + {exec} + {multi} {del asdf*} {incr notifications} - {del asdf*} + {exec} {multi} + {del asdf*} {incr notifications} + {exec} + {multi} {set asdf4 4} + {incr notifications} {exec} } close_replication_stream $repl @@ -229,20 +244,24 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} + {set timer-maxmemory-volatile-start 1 PXAT *} {incr notifications} {incr notifications} - {set timer-maxmemory-volatile-start 1 PXAT *} {incr timer-maxmemory-middle} + {set timer-maxmemory-volatile-end 1 PXAT *} {incr notifications} {incr notifications} - {set timer-maxmemory-volatile-end 1 PXAT *} {exec} - {incr notifications} + {multi} {del timer-maxmemory-volatile-*} {incr notifications} + {exec} + {multi} {del timer-maxmemory-volatile-*} + {incr notifications} + {exec} } close_replication_stream $repl @@ -256,15 +275,15 @@ tags "modules" { $master propagate-test.timer-eval assert_replication_stream $repl { - {select *} {multi} - {incr notifications} + {select *} {incrby timer-eval-start 1} {incr notifications} {set foo bar} - {incr timer-eval-middle} {incr notifications} + {incr timer-eval-middle} {incrby timer-eval-end 1} + {incr notifications} {exec} } close_replication_stream $repl @@ -282,8 +301,8 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incrby timer-nested-start 1} {incrby timer-nested-end 1} {exec} @@ -307,16 +326,15 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incrby timer-nested-start 1} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} {incr counter-3} {incr counter-4} - {incr notifications} {incr after-call} {incr notifications} {incr before-call-2} @@ -328,6 +346,7 @@ tags "modules" { {incr after-call-2} {incr notifications} {incr timer-nested-middle} + {incr notifications} {incrby timer-nested-end 1} {exec} } @@ -350,23 +369,23 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incr a-from-thread} - {incr notifications} {incr thread-call} + {incr notifications} {incr b-from-thread} {exec} {multi} {incr a-from-thread} - {incr notifications} {incr thread-call} + {incr notifications} {incr b-from-thread} {exec} {multi} {incr a-from-thread} - {incr notifications} {incr thread-call} + {incr notifications} {incr b-from-thread} {exec} } @@ -385,13 +404,13 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incr thread-detached-before} - {incr notifications} {incr thread-detached-1} {incr notifications} {incr thread-detached-2} + {incr notifications} {incr thread-detached-after} {exec} } @@ -405,18 +424,18 @@ tags "modules" { $master propagate-test.mixed assert_replication_stream $repl { - {select *} {multi} + {select *} {incr counter-1} {incr counter-2} {exec} {multi} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} - {incr notifications} {incr after-call} + {incr notifications} {exec} } close_replication_stream $repl @@ -431,18 +450,18 @@ tags "modules" { redis.call("propagate-test.mixed"); return "OK" } 0 ] {OK} assert_replication_stream $repl { - {select *} {multi} + {select *} {incr counter-1} {incr counter-2} - {incr notifications} {set x y} {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} - {incr notifications} {incr after-call} + {incr notifications} {exec} } close_replication_stream $repl @@ -456,18 +475,18 @@ tags "modules" { $master propagate-test.mixed assert_replication_stream $repl { - {select *} {multi} + {select *} {incr counter-1} {incr counter-2} {exec} {multi} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} - {incr notifications} {incr after-call} + {incr notifications} {exec} } close_replication_stream $repl @@ -482,18 +501,18 @@ tags "modules" { $master propagate-test.mixed assert_replication_stream $repl { - {select *} {multi} + {select *} {incr counter-1} {incr counter-2} {exec} {multi} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} - {incr notifications} {incr after-call} + {incr notifications} {exec} } close_replication_stream $repl @@ -515,26 +534,25 @@ tags "modules" { } assert_replication_stream $repl { - {select *} {multi} + {select *} {incr counter-1} {incr counter-2} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} - {incr notifications} {incr after-call} + {incr notifications} {exec} {multi} {incrby timer-nested-start 1} - {incr notifications} {incr using-call} + {incr notifications} {incr counter-1} {incr counter-2} {incr counter-3} {incr counter-4} - {incr notifications} {incr after-call} {incr notifications} {incr before-call-2} @@ -546,6 +564,7 @@ tags "modules" { {incr after-call-2} {incr notifications} {incr timer-nested-middle} + {incr notifications} {incrby timer-nested-end 1} {exec} } @@ -566,8 +585,8 @@ tags "modules" { $master propagate-test.incr k1 assert_replication_stream $repl { - {select *} {multi} + {select *} {del k1} {propagate-test.incr k1} {exec} @@ -580,6 +599,71 @@ tags "modules" { assert_equal [$replica ttl k1] -1 } + test {module notification on set} { + set repl [attach_to_replication_stream] + + $master SADD s foo + + wait_for_condition 500 10 { + [$replica SCARD s] eq "1" + } else { + fail "Failed to wait for set to be replicated" + } + + $master SPOP s 1 + + wait_for_condition 500 10 { + [$replica SCARD s] eq "0" + } else { + fail "Failed to wait for set to be replicated" + } + + # Currently the `del` command comes after the notification. + # When we fix spop to fire notification at the end (like all other commands), + # the `del` will come first. + assert_replication_stream $repl { + {multi} + {select *} + {sadd s foo} + {incr notifications} + {exec} + {multi} + {incr notifications} + {del s} + {incr notifications} + {exec} + } + close_replication_stream $repl + } + + test {module key miss notification do not cause read command to be replicated} { + set repl [attach_to_replication_stream] + + $master flushall + + $master get unexisting_key + + wait_for_condition 500 10 { + [$replica get missed] eq "1" + } else { + fail "Failed to wait for set to be replicated" + } + + # Test is checking a wrong!!! behavior that causes a read command to be replicated to replica/aof. + # We keep the test to verify that such a wrong behavior does not cause any crashes. + assert_replication_stream $repl { + {select *} + {flushall} + {multi} + {incr missed} + {incr notifications} + {get unexisting_key} + {exec} + } + + close_replication_stream $repl + } + test "Unload the module - propagate-test/testkeyspace" { assert_equal {OK} [r module unload propagate-test] assert_equal {OK} [r module unload testkeyspace] diff --git a/tests/unit/multi.tcl b/tests/unit/multi.tcl index 63d85d26b..26ab8e571 100644 --- a/tests/unit/multi.tcl +++ b/tests/unit/multi.tcl @@ -421,8 +421,8 @@ start_server {tags {"multi"}} { r exec assert_replication_stream $repl { - {select *} {multi} + {select *} {set foo{t} bar} {set foo2{t} bar2} {set foo3{t} bar3} @@ -446,8 +446,8 @@ start_server {tags {"multi"}} { r exec assert_replication_stream $repl { - {select *} {multi} + {select *} {set foo{t} bar} {select *} {set foo2{t} bar2} @@ -904,8 +904,8 @@ start_server {overrides {appendonly {yes} appendfilename {appendonly.aof} append r flushall r exec assert_aof_content $aof { - {select *} {multi} + {select *} {set *} {flushall} {exec} |