diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 5f114c5dc..2f8021e66 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -55,6 +55,7 @@ set ::all_tests { unit/memefficiency unit/hyperloglog unit/lazyfree + unit/wait } # Index to the next test to run in the ::all_tests list. set ::next_test 0 diff --git a/tests/unit/wait.tcl b/tests/unit/wait.tcl new file mode 100644 index 000000000..e2f5d2942 --- /dev/null +++ b/tests/unit/wait.tcl @@ -0,0 +1,42 @@ +start_server {tags {"wait"}} { +start_server {} { + set slave [srv 0 client] + set slave_host [srv 0 host] + set slave_port [srv 0 port] + set master [srv -1 client] + set master_host [srv -1 host] + set master_port [srv -1 port] + + test {Setup slave} { + $slave slaveof $master_host $master_port + wait_for_condition 50 100 { + [s 0 master_link_status] eq {up} + } else { + fail "Replication not started." + } + } + + test {WAIT should acknowledge 1 additional copy of the data} { + $master set foo 0 + $master incr foo + $master incr foo + $master incr foo + assert {[$master wait 1 5000] == 1} + assert {[$slave get foo] == 3} + } + + test {WAIT should not acknowledge 2 additional copies of the data} { + $master incr foo + assert {[$master wait 2 1000] <= 1} + } + + test {WAIT should not acknowledge 1 additional copy if slave is blocked} { + exec src/redis-cli -h $slave_host -p $slave_port debug sleep 5 > /dev/null 2> /dev/null & + after 1000 ;# Give redis-cli the time to execute the command. + $master set foo 0 + $master incr foo + $master incr foo + $master incr foo + assert {[$master wait 1 3000] == 0} + } +}}