1# Replica migration test. 2# Check that orphaned masters are joined by replicas of masters having 3# multiple replicas attached, according to the migration barrier settings. 4 5source "../tests/includes/init-tests.tcl" 6 7# Create a cluster with 5 master and 10 slaves, so that we have 2 8# slaves for each master. 9test "Create a 5 nodes cluster" { 10 create_cluster 5 10 11} 12 13test "Cluster is up" { 14 assert_cluster_state ok 15} 16 17test "Each master should have two replicas attached" { 18 foreach_redis_id id { 19 if {$id < 5} { 20 wait_for_condition 1000 50 { 21 [llength [lindex [R 0 role] 2]] == 2 22 } else { 23 fail "Master #$id does not have 2 slaves as expected" 24 } 25 } 26 } 27} 28 29test "Killing all the slaves of master #0 and #1" { 30 kill_instance redis 5 31 kill_instance redis 10 32 kill_instance redis 6 33 kill_instance redis 11 34 after 4000 35} 36 37foreach_redis_id id { 38 if {$id < 5} { 39 test "Master #$id should have at least one replica" { 40 wait_for_condition 1000 50 { 41 [llength [lindex [R $id role] 2]] >= 1 42 } else { 43 fail "Master #$id has no replicas" 44 } 45 } 46 } 47} 48 49# Now test the migration to a master which used to be a slave, after 50# a failver. 51 52source "../tests/includes/init-tests.tcl" 53 54# Create a cluster with 5 master and 10 slaves, so that we have 2 55# slaves for each master. 56test "Create a 5 nodes cluster" { 57 create_cluster 5 10 58} 59 60test "Cluster is up" { 61 assert_cluster_state ok 62} 63 64test "Kill slave #7 of master #2. Only slave left is #12 now" { 65 kill_instance redis 7 66} 67 68set current_epoch [CI 1 cluster_current_epoch] 69 70test "Killing master node #2, #12 should failover" { 71 kill_instance redis 2 72} 73 74test "Wait for failover" { 75 wait_for_condition 1000 50 { 76 [CI 1 cluster_current_epoch] > $current_epoch 77 } else { 78 fail "No failover detected" 79 } 80} 81 82test "Cluster should eventually be up again" { 83 assert_cluster_state ok 84} 85 86test "Cluster is writable" { 87 cluster_write_test 1 88} 89 90test "Instance 12 is now a master without slaves" { 91 assert {[RI 12 role] eq {master}} 92} 93 94# The remaining instance is now without slaves. Some other slave 95# should migrate to it. 96 97test "Master #12 should get at least one migrated replica" { 98 wait_for_condition 1000 50 { 99 [llength [lindex [R 12 role] 2]] >= 1 100 } else { 101 fail "Master #12 has no replicas" 102 } 103} 104