diff options
author | antirez <antirez@gmail.com> | 2018-05-15 17:33:21 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-05-15 17:33:29 +0200 |
commit | 8327ccef0e2775b243a5d22dfcf1e45c08ddf47e (patch) | |
tree | ea12b600667b0c056aeeb814e58b9f073d5bb2d7 | |
parent | 25f017e563c0e1ef9837604a96e4655b021bad32 (diff) | |
download | redis-8327ccef0e2775b243a5d22dfcf1e45c08ddf47e.tar.gz |
Test: replication test blocking lists/zsets ops.
-rw-r--r-- | tests/helpers/bg_block_op.tcl | 51 | ||||
-rw-r--r-- | tests/integration/block-repl.tcl | 58 | ||||
-rw-r--r-- | tests/test_helper.tcl | 1 |
3 files changed, 110 insertions, 0 deletions
diff --git a/tests/helpers/bg_block_op.tcl b/tests/helpers/bg_block_op.tcl new file mode 100644 index 000000000..6553a9abd --- /dev/null +++ b/tests/helpers/bg_block_op.tcl @@ -0,0 +1,51 @@ +source tests/support/redis.tcl +source tests/support/util.tcl + +# This function sometimes writes sometimes blocking-reads from lists/sorted +# sets. There are multiple processes like this executing at the same time +# so that we have some chance to trap some corner condition if there is +# a regression. For this to happen it is important that we narrow the key +# space to just a few elements, and balance the operations so that it is +# unlikely that lists and zsets just get more data without ever causing +# blocking. +proc bg_block_op {host port db ops} { + set r [redis $host $port] + $r select $db + + for {set j 0} {$j < $ops} {incr j} { + + # List side + set k list_[randomInt 10] + set k2 list_[randomInt 10] + set v [randomValue] + + randpath { + randpath { + $r rpush $k $v + } { + $r lpush $k $v + } + } { + $r blpop $k 2 + } { + $r blpop $k $k2 2 + } + + # Zset side + set k zset_[randomInt 10] + set k2 zset_[randomInt 10] + + randpath { + $r zadd $k [randomInt 10000] $v + } { + # Duplicate to balance the probability to push data + $r zadd $k [randomInt 10000] $v + } { + $r bzpopmin $k 2 + } { + $r bzpopmax $k 2 + } + } +} + +bg_block_op [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] diff --git a/tests/integration/block-repl.tcl b/tests/integration/block-repl.tcl new file mode 100644 index 000000000..21015bbad --- /dev/null +++ b/tests/integration/block-repl.tcl @@ -0,0 +1,58 @@ +# Test replication of blocking lists and zset operations. +# Unlike stream operations such operations are "pop" style, so they consume +# the list or sorted set, and must be replicated correctly. + +proc start_bg_block_op {host port db ops} { + set tclsh [info nameofexecutable] + exec $tclsh tests/helpers/bg_block_op.tcl $host $port $db $ops & +} + +proc stop_bg_block_op {handle} { + catch {exec /bin/kill -9 $handle} +} + +start_server {tags {"repl"}} { + start_server {} { + set master [srv -1 client] + set master_host [srv -1 host] + set master_port [srv -1 port] + set slave [srv 0 client] + + set load_handle0 [start_bg_block_op $master_host $master_port 9 100000] + set load_handle1 [start_bg_block_op $master_host $master_port 11 100000] + set load_handle2 [start_bg_block_op $master_host $master_port 12 100000] + + test {First server should have role slave after SLAVEOF} { + $slave slaveof $master_host $master_port + after 1000 + s 0 role + } {slave} + + test {Test replication with parallel clients writing in differnet DBs} { + after 25000 + stop_bg_block_op $load_handle0 + stop_bg_block_op $load_handle1 + stop_bg_block_op $load_handle2 + set retry 10 + while {$retry && ([$master debug digest] ne [$slave debug digest])}\ + { + after 1000 + incr retry -1 + } + + if {[$master debug digest] ne [$slave debug digest]} { + set csv1 [csvdump r] + set csv2 [csvdump {r -1}] + set fd [open /tmp/repldump1.txt w] + puts -nonewline $fd $csv1 + close $fd + set fd [open /tmp/repldump2.txt w] + puts -nonewline $fd $csv2 + close $fd + puts "Master - Slave inconsistency" + puts "Run diff -u against /tmp/repldump*.txt for more info" + } + assert_equal [r debug digest] [r -1 debug digest] + } + } +} diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 93a19f85b..8b4d1eacf 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -34,6 +34,7 @@ set ::all_tests { unit/multi unit/quit unit/aofrw + integration/block-repl integration/replication integration/replication-2 integration/replication-3 |