123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- set testmodule [file normalize tests/modules/propagate.so]
- tags "modules" {
- test {Modules can propagate in async and threaded contexts} {
- start_server [list overrides [list loadmodule "$testmodule"]] {
- set replica [srv 0 client]
- set replica_host [srv 0 host]
- set replica_port [srv 0 port]
- start_server [list overrides [list loadmodule "$testmodule"]] {
- set master [srv 0 client]
- set master_host [srv 0 host]
- set master_port [srv 0 port]
- # Start the replication process...
- $replica replicaof $master_host $master_port
- wait_for_sync $replica
- after 1000
- test {module propagates from timer} {
- set repl [attach_to_replication_stream]
- $master propagate-test.timer
- wait_for_condition 5000 10 {
- [$replica get timer] eq "3"
- } else {
- fail "The two counters don't match the expected value."
- }
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr timer}
- {exec}
- {multi}
- {incr timer}
- {exec}
- {multi}
- {incr timer}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates nested ctx case1} {
- set repl [attach_to_replication_stream]
- $master del timer-nested-start
- $master del timer-nested-end
- $master propagate-test.timer-nested
- wait_for_condition 5000 10 {
- [$replica get timer-nested-end] eq "1"
- } else {
- fail "The two counters don't match the expected value."
- }
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incrby timer-nested-start 1}
- {incrby timer-nested-end 1}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates nested ctx case2} {
- set repl [attach_to_replication_stream]
- $master del timer-nested-start
- $master del timer-nested-end
- $master propagate-test.timer-nested-repl
- wait_for_condition 5000 10 {
- [$replica get timer-nested-end] eq "1"
- } else {
- fail "The two counters don't match the expected value."
- }
- # Note the 'after-call' and 'timer-nested-start' propagation below is out of order (known limitation)
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr using-call}
- {incr counter-1}
- {incr counter-2}
- {incr after-call}
- {incr counter-3}
- {incr counter-4}
- {incrby timer-nested-start 1}
- {incrby timer-nested-end 1}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates from thread} {
- set repl [attach_to_replication_stream]
- $master propagate-test.thread
- wait_for_condition 5000 10 {
- [$replica get a-from-thread] eq "3"
- } else {
- fail "The two counters don't match the expected value."
- }
- assert_replication_stream $repl {
- {select *}
- {incr a-from-thread}
- {incr b-from-thread}
- {incr a-from-thread}
- {incr b-from-thread}
- {incr a-from-thread}
- {incr b-from-thread}
- }
- close_replication_stream $repl
- }
- test {module propagates from from command} {
- set repl [attach_to_replication_stream]
- $master propagate-test.simple
- $master propagate-test.mixed
- # Note the 'after-call' propagation below is out of order (known limitation)
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr counter-1}
- {incr counter-2}
- {exec}
- {multi}
- {incr using-call}
- {incr after-call}
- {incr counter-1}
- {incr counter-2}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates from from command after good EVAL} {
- set repl [attach_to_replication_stream]
- assert_equal [ $master eval { return "hello" } 0 ] {hello}
- $master propagate-test.simple
- $master propagate-test.mixed
- # Note the 'after-call' propagation below is out of order (known limitation)
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr counter-1}
- {incr counter-2}
- {exec}
- {multi}
- {incr using-call}
- {incr after-call}
- {incr counter-1}
- {incr counter-2}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates from from command after bad EVAL} {
- set repl [attach_to_replication_stream]
- catch { $master eval { return "hello" } -12 } e
- assert_equal $e {ERR Number of keys can't be negative}
- $master propagate-test.simple
- $master propagate-test.mixed
- # Note the 'after-call' propagation below is out of order (known limitation)
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr counter-1}
- {incr counter-2}
- {exec}
- {multi}
- {incr using-call}
- {incr after-call}
- {incr counter-1}
- {incr counter-2}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module propagates from from multi-exec} {
- set repl [attach_to_replication_stream]
- $master multi
- $master propagate-test.simple
- $master propagate-test.mixed
- $master exec
- wait_for_ofs_sync $master $replica
- # Note the 'after-call' propagation below is out of order (known limitation)
- assert_replication_stream $repl {
- {select *}
- {multi}
- {incr counter-1}
- {incr counter-2}
- {incr using-call}
- {incr after-call}
- {incr counter-1}
- {incr counter-2}
- {exec}
- }
- close_replication_stream $repl
- }
- test {module RM_Call of expired key propagation} {
- $master debug set-active-expire 0
- $master set k1 900 px 100
- wait_for_ofs_sync $master $replica
- after 110
- set repl [attach_to_replication_stream]
- $master propagate-test.incr k1
- wait_for_ofs_sync $master $replica
- assert_replication_stream $repl {
- {select *}
- {del k1}
- {propagate-test.incr k1}
- }
- close_replication_stream $repl
- assert_equal [$master get k1] 1
- assert_equal [$master ttl k1] -1
- assert_equal [$replica get k1] 1
- assert_equal [$replica ttl k1] -1
- }
- assert_equal [s -1 unexpected_error_replies] 0
- }
- }
- }
- }
- tags "modules aof" {
- test {Modules RM_Replicate replicates MULTI/EXEC correctly} {
- start_server [list overrides [list loadmodule "$testmodule"]] {
- # Enable the AOF
- r config set appendonly yes
- r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
- waitForBgrewriteaof r
- r propagate-test.simple
- r propagate-test.mixed
- r multi
- r propagate-test.simple
- r propagate-test.mixed
- r exec
- # Load the AOF
- r debug loadaof
- assert_equal [s 0 unexpected_error_replies] 0
- }
- }
- }
|