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 6source "../tests/includes/init-tests.tcl" 7 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. 10test "Create a 5 nodes cluster" { 11 create_cluster 5 15 12} 13 14test "Cluster is up" { 15 assert_cluster_state ok 16} 17 18test "Each master should have at least two replicas attached" { 19 foreach_redis_id id { 20 if {$id < 5} { 21 wait_for_condition 1000 50 { 22 [llength [lindex [R 0 role] 2]] >= 2 23 } else { 24 fail "Master #$id does not have 2 slaves as expected" 25 } 26 } 27 } 28} 29 30test "Set allow-replica-migration no" { 31 foreach_redis_id id { 32 R $id CONFIG SET cluster-allow-replica-migration no 33 } 34} 35 36set master0_id [dict get [get_myself 0] id] 37test "Resharding all the master #0 slots away from it" { 38 set output [exec \ 39 ../../../src/redis-cli --cluster rebalance \ 40 127.0.0.1:[get_instance_attrib redis 0 port] \ 41 {*}[rediscli_tls_config "../../../tests"] \ 42 --cluster-weight ${master0_id}=0 >@ stdout ] 43} 44 45test "Wait cluster to be stable" { 46 wait_for_condition 1000 50 { 47 [catch {exec ../../../src/redis-cli --cluster \ 48 check 127.0.0.1:[get_instance_attrib redis 0 port] \ 49 {*}[rediscli_tls_config "../../../tests"] \ 50 }] == 0 51 } else { 52 fail "Cluster doesn't stabilize" 53 } 54} 55 56test "Master #0 still should have its replicas" { 57 assert { [llength [lindex [R 0 role] 2]] >= 2 } 58} 59 60test "Each master should have at least two replicas attached" { 61 foreach_redis_id id { 62 if {$id < 5} { 63 wait_for_condition 1000 50 { 64 [llength [lindex [R 0 role] 2]] >= 2 65 } else { 66 fail "Master #$id does not have 2 slaves as expected" 67 } 68 } 69 } 70} 71 72