"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/02-slaves-reconf.tcl" (21 Sep 2022, 2832 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 # Check that slaves are reconfigured at a latter time if they are partitioned.
    2 #
    3 # Here we should test:
    4 # 1) That slaves point to the new master after failover.
    5 # 2) That partitioned slaves point to new master when they are partitioned
    6 #    away during failover and return at a latter time.
    7 
    8 source "../tests/includes/init-tests.tcl"
    9 
   10 proc 02_test_slaves_replication {} {
   11     uplevel 1 {
   12         test "Check that slaves replicate from current master" {
   13             set master_port [RPort $master_id]
   14             foreach_redis_id id {
   15                 if {$id == $master_id} continue
   16                 if {[instance_is_killed redis $id]} continue
   17                 wait_for_condition 1000 50 {
   18                     ([RI $id master_port] == $master_port) &&
   19                     ([RI $id master_link_status] eq {up})
   20                 } else {
   21                     fail "Redis slave $id is replicating from wrong master"
   22                 }
   23             }
   24         }
   25     }
   26 }
   27 
   28 proc 02_crash_and_failover {} {
   29     uplevel 1 {
   30         test "Crash the master and force a failover" {
   31             set old_port [RPort $master_id]
   32             set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   33             assert {[lindex $addr 1] == $old_port}
   34             kill_instance redis $master_id
   35             foreach_sentinel_id id {
   36                 wait_for_condition 1000 50 {
   37                     [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
   38                 } else {
   39                     fail "At least one Sentinel did not receive failover info"
   40                 }
   41             }
   42             restart_instance redis $master_id
   43             set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   44             set master_id [get_instance_id_by_port redis [lindex $addr 1]]
   45         }
   46     }
   47 }
   48 
   49 02_test_slaves_replication
   50 02_crash_and_failover
   51 
   52 foreach_sentinel_id id {
   53     S $id sentinel debug info-period 100
   54     S $id sentinel debug default-down-after 1000
   55     S $id sentinel debug publish-period 100
   56 }
   57 
   58 02_test_slaves_replication
   59 
   60 test "Kill a slave instance" {
   61     foreach_redis_id id {
   62         if {$id == $master_id} continue
   63         set killed_slave_id $id
   64         kill_instance redis $id
   65         break
   66     }
   67 }
   68 
   69 02_crash_and_failover
   70 02_test_slaves_replication
   71 
   72 test "Wait for failover to end" {
   73     set inprogress 1
   74     while {$inprogress} {
   75         set inprogress 0
   76         foreach_sentinel_id id {
   77             if {[dict exists [S $id SENTINEL MASTER mymaster] failover-state]} {
   78                 incr inprogress
   79             }
   80         }
   81         if {$inprogress} {after 100}
   82     }
   83 }
   84 
   85 test "Restart killed slave and test replication of slaves again..." {
   86     restart_instance redis $killed_slave_id
   87 }
   88 
   89 # Now we check if the slave rejoining the partition is reconfigured even
   90 # if the failover finished.
   91 02_test_slaves_replication