06-slave-stop-cond.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Slave stop condition test
  2. # Check that if there is a disconnection time limit, the slave will not try
  3. # to failover its master.
  4. source "../tests/includes/init-tests.tcl"
  5. # Create a cluster with 5 master and 5 slaves.
  6. test "Create a 5 nodes cluster" {
  7. create_cluster 5 5
  8. }
  9. test "Cluster is up" {
  10. assert_cluster_state ok
  11. }
  12. test "The first master has actually one slave" {
  13. assert {[llength [lindex [R 0 role] 2]] == 1}
  14. }
  15. test {Slaves of #0 is instance #5 as expected} {
  16. set port0 [get_instance_attrib redis 0 port]
  17. assert {[lindex [R 5 role] 2] == $port0}
  18. }
  19. test "Instance #5 synced with the master" {
  20. wait_for_condition 1000 50 {
  21. [RI 5 master_link_status] eq {up}
  22. } else {
  23. fail "Instance #5 master link status is not up"
  24. }
  25. }
  26. test "Lower the slave validity factor of #5 to the value of 2" {
  27. assert {[R 5 config set cluster-slave-validity-factor 2] eq {OK}}
  28. }
  29. test "Break master-slave link and prevent further reconnections" {
  30. # Stop the slave with a multi/exec transaction so that the master will
  31. # be killed as soon as it can accept writes again.
  32. R 5 multi
  33. R 5 client kill 127.0.0.1:$port0
  34. # here we should sleep 6 or more seconds (node_timeout * slave_validity)
  35. # but the actual validity time is actually incremented by the
  36. # repl-ping-slave-period value which is 10 seconds by default. So we
  37. # need to wait more than 16 seconds.
  38. R 5 debug sleep 20
  39. R 5 deferred 1
  40. R 5 exec
  41. # Prevent the master from accepting new slaves.
  42. # Use a large pause value since we'll kill it anyway.
  43. R 0 CLIENT PAUSE 60000
  44. # Wait for the slave to return available again
  45. R 5 deferred 0
  46. assert {[R 5 read] eq {OK OK}}
  47. # Kill the master so that a reconnection will not be possible.
  48. kill_instance redis 0
  49. }
  50. test "Slave #5 is reachable and alive" {
  51. assert {[R 5 ping] eq {PONG}}
  52. }
  53. test "Slave #5 should not be able to failover" {
  54. after 10000
  55. assert {[RI 5 role] eq {slave}}
  56. }
  57. test "Cluster should be down" {
  58. assert_cluster_state fail
  59. }