12-replica-migration-2.tcl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Replica migration test #2.
  2. #
  3. # Check that the status of master that can be targeted by replica migration
  4. # is acquired again, after being getting slots again, in a cluster where the
  5. # other masters have slaves.
  6. source "../tests/includes/init-tests.tcl"
  7. source "../../../tests/support/cli.tcl"
  8. # Create a cluster with 5 master and 15 slaves, to make sure there are no
  9. # empty masters and make rebalancing simpler to handle during the test.
  10. test "Create a 5 nodes cluster" {
  11. create_cluster 5 15
  12. }
  13. test "Cluster is up" {
  14. assert_cluster_state ok
  15. }
  16. test "Each master should have at least two replicas attached" {
  17. foreach_redis_id id {
  18. if {$id < 5} {
  19. wait_for_condition 1000 50 {
  20. [llength [lindex [R 0 role] 2]] >= 2
  21. } else {
  22. fail "Master #$id does not have 2 slaves as expected"
  23. }
  24. }
  25. }
  26. }
  27. test "Set allow-replica-migration yes" {
  28. foreach_redis_id id {
  29. R $id CONFIG SET cluster-allow-replica-migration yes
  30. }
  31. }
  32. set master0_id [dict get [get_myself 0] id]
  33. test "Resharding all the master #0 slots away from it" {
  34. set output [exec \
  35. ../../../src/redis-cli --cluster rebalance \
  36. 127.0.0.1:[get_instance_attrib redis 0 port] \
  37. {*}[rediscli_tls_config "../../../tests"] \
  38. --cluster-weight ${master0_id}=0 >@ stdout ]
  39. }
  40. test "Master #0 should lose its replicas" {
  41. wait_for_condition 1000 50 {
  42. [llength [lindex [R 0 role] 2]] == 0
  43. } else {
  44. fail "Master #0 still has replicas"
  45. }
  46. }
  47. test "Resharding back some slot to master #0" {
  48. # Wait for the cluster config to propagate before attempting a
  49. # new resharding.
  50. after 10000
  51. set output [exec \
  52. ../../../src/redis-cli --cluster rebalance \
  53. 127.0.0.1:[get_instance_attrib redis 0 port] \
  54. {*}[rediscli_tls_config "../../../tests"] \
  55. --cluster-weight ${master0_id}=.01 \
  56. --cluster-use-empty-masters >@ stdout]
  57. }
  58. test "Master #0 should re-acquire one or more replicas" {
  59. wait_for_condition 1000 50 {
  60. [llength [lindex [R 0 role] 2]] >= 1
  61. } else {
  62. fail "Master #0 has no has replicas"
  63. }
  64. }