12.1-replica-migration-3.tcl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Replica migration test #2.
  2. #
  3. # Check that if 'cluster-allow-replica-migration' is set to 'no', slaves do not
  4. # migrate when master becomes empty.
  5. source "../tests/includes/init-tests.tcl"
  6. # Create a cluster with 5 master and 15 slaves, to make sure there are no
  7. # empty masters and make rebalancing simpler to handle during the test.
  8. test "Create a 5 nodes cluster" {
  9. create_cluster 5 15
  10. }
  11. test "Cluster is up" {
  12. assert_cluster_state ok
  13. }
  14. test "Each master should have at least two replicas attached" {
  15. foreach_redis_id id {
  16. if {$id < 5} {
  17. wait_for_condition 1000 50 {
  18. [llength [lindex [R 0 role] 2]] >= 2
  19. } else {
  20. fail "Master #$id does not have 2 slaves as expected"
  21. }
  22. }
  23. }
  24. }
  25. test "Set allow-replica-migration no" {
  26. foreach_redis_id id {
  27. R $id CONFIG SET cluster-allow-replica-migration no
  28. }
  29. }
  30. set master0_id [dict get [get_myself 0] id]
  31. test "Resharding all the master #0 slots away from it" {
  32. set output [exec \
  33. ../../../src/redis-cli --cluster rebalance \
  34. 127.0.0.1:[get_instance_attrib redis 0 port] \
  35. {*}[rediscli_tls_config "../../../tests"] \
  36. --cluster-weight ${master0_id}=0 >@ stdout ]
  37. }
  38. test "Wait cluster to be stable" {
  39. wait_for_condition 1000 50 {
  40. [catch {exec ../../../src/redis-cli --cluster \
  41. check 127.0.0.1:[get_instance_attrib redis 0 port] \
  42. {*}[rediscli_tls_config "../../../tests"] \
  43. }] == 0
  44. } else {
  45. fail "Cluster doesn't stabilize"
  46. }
  47. }
  48. test "Master #0 still should have its replicas" {
  49. assert { [llength [lindex [R 0 role] 2]] >= 2 }
  50. }
  51. test "Each master should have at least two replicas attached" {
  52. foreach_redis_id id {
  53. if {$id < 5} {
  54. wait_for_condition 1000 50 {
  55. [llength [lindex [R 0 role] 2]] >= 2
  56. } else {
  57. fail "Master #$id does not have 2 slaves as expected"
  58. }
  59. }
  60. }
  61. }