"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/cluster/tests/12-replica-migration-2.tcl" (21 Sep 2022, 2320 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.
    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 
    7 source "../tests/includes/init-tests.tcl"
    8 source "../../../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.
   12 test "Create a 5 nodes cluster" {
   13     cluster_create_with_continuous_slots 5 15
   14 }
   15 
   16 test "Cluster is up" {
   17     assert_cluster_state ok
   18 }
   19 
   20 test "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 $id role] 2]] >= 2
   25             } else {
   26                 fail "Master #$id does not have 2 slaves as expected"
   27             }
   28         }
   29     }
   30 }
   31 
   32 test "Set allow-replica-migration yes" {
   33     foreach_redis_id id {
   34         R $id CONFIG SET cluster-allow-replica-migration yes
   35     }
   36 }
   37 
   38 set master0_id [dict get [get_myself 0] id]
   39 test "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 
   48 test "Master #0 who lost all slots should turn into a replica without replicas" {
   49     wait_for_condition 1000 50 {
   50         [RI 0 role] == "slave" && [RI 0 connected_slaves] == 0
   51     } else {
   52         puts [R 0 info replication]
   53         fail "Master #0 didn't turn itself into a replica"
   54     }
   55 }
   56 
   57 test "Resharding back some slot to master #0" {
   58     # Wait for the cluster config to propagate before attempting a
   59     # new resharding.
   60     after 10000
   61     set output [exec \
   62         ../../../src/redis-cli --cluster rebalance \
   63         127.0.0.1:[get_instance_attrib redis 0 port] \
   64         {*}[rediscli_tls_config "../../../tests"] \
   65         --cluster-weight ${master0_id}=.01 \
   66         --cluster-use-empty-masters  >@ stdout]
   67 }
   68 
   69 test "Master #0 should re-acquire one or more replicas" {
   70     wait_for_condition 1000 50 {
   71         [llength [lindex [R 0 role] 2]] >= 1
   72     } else {
   73         fail "Master #0 has no has replicas"
   74     }
   75 }