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