"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/cluster/tests/07-replica-migration.tcl" (21 Sep 2022, 2476 Bytes) of package /linux/misc/redis-7.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    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 
    5 source "../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.
    9 test "Create a 5 nodes cluster" {
   10     create_cluster 5 10
   11 }
   12 
   13 test "Cluster is up" {
   14     assert_cluster_state ok
   15 }
   16 
   17 test "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 $id role] 2]] == 2
   22             } else {
   23                 fail "Master #$id does not have 2 slaves as expected"
   24             }
   25         }
   26     }
   27 }
   28 
   29 test "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 
   37 foreach_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 
   52 source "../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.
   56 test "Create a 5 nodes cluster" {
   57     create_cluster 5 10
   58 }
   59 
   60 test "Cluster is up" {
   61     assert_cluster_state ok
   62 }
   63 
   64 test "Kill slave #7 of master #2. Only slave left is #12 now" {
   65     kill_instance redis 7
   66 }
   67 
   68 set current_epoch [CI 1 cluster_current_epoch]
   69 
   70 test "Killing master node #2, #12 should failover" {
   71     kill_instance redis 2
   72 }
   73 
   74 test "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 
   82 test "Cluster should eventually be up again" {
   83     assert_cluster_state ok
   84 }
   85 
   86 test "Cluster is writable" {
   87     cluster_write_test 1
   88 }
   89 
   90 test "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 
   97 test "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 }