wait.tcl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. source tests/support/cli.tcl
  2. start_server {tags {"wait"}} {
  3. start_server {} {
  4. set slave [srv 0 client]
  5. set slave_host [srv 0 host]
  6. set slave_port [srv 0 port]
  7. set master [srv -1 client]
  8. set master_host [srv -1 host]
  9. set master_port [srv -1 port]
  10. test {Setup slave} {
  11. $slave slaveof $master_host $master_port
  12. wait_for_condition 50 100 {
  13. [s 0 master_link_status] eq {up}
  14. } else {
  15. fail "Replication not started."
  16. }
  17. }
  18. test {WAIT should acknowledge 1 additional copy of the data} {
  19. $master set foo 0
  20. $master incr foo
  21. $master incr foo
  22. $master incr foo
  23. assert {[$master wait 1 5000] == 1}
  24. assert {[$slave get foo] == 3}
  25. }
  26. test {WAIT should not acknowledge 2 additional copies of the data} {
  27. $master incr foo
  28. assert {[$master wait 2 1000] <= 1}
  29. }
  30. test {WAIT should not acknowledge 1 additional copy if slave is blocked} {
  31. set cmd [rediscli $slave_port "-h $slave_host debug sleep 5"]
  32. exec {*}$cmd > /dev/null 2> /dev/null &
  33. after 1000 ;# Give redis-cli the time to execute the command.
  34. $master set foo 0
  35. $master incr foo
  36. $master incr foo
  37. $master incr foo
  38. assert {[$master wait 1 3000] == 0}
  39. }
  40. }}