"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/05-manual.tcl" (21 Sep 2022, 1557 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 # Test manual failover
    2 
    3 source "../tests/includes/init-tests.tcl"
    4 
    5 foreach_sentinel_id id {
    6     S $id sentinel debug info-period 2000
    7     S $id sentinel debug default-down-after 6000
    8     S $id sentinel debug publish-period 1000
    9 }
   10 
   11 test "Manual failover works" {
   12     set old_port [RPort $master_id]
   13     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   14     assert {[lindex $addr 1] == $old_port}
   15     catch {S 0 SENTINEL FAILOVER mymaster} reply
   16     assert {$reply eq "OK"}
   17     foreach_sentinel_id id {
   18         wait_for_condition 1000 50 {
   19             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
   20         } else {
   21             fail "At least one Sentinel did not receive failover info"
   22         }
   23     }
   24     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   25     set master_id [get_instance_id_by_port redis [lindex $addr 1]]
   26 }
   27 
   28 test "New master [join $addr {:}] role matches" {
   29     assert {[RI $master_id role] eq {master}}
   30 }
   31 
   32 test "All the other slaves now point to the new master" {
   33     foreach_redis_id id {
   34         if {$id != $master_id && $id != 0} {
   35             wait_for_condition 1000 50 {
   36                 [RI $id master_port] == [lindex $addr 1]
   37             } else {
   38                 fail "Redis ID $id not configured to replicate with new master"
   39             }
   40         }
   41     }
   42 }
   43 
   44 test "The old master eventually gets reconfigured as a slave" {
   45     wait_for_condition 1000 50 {
   46         [RI 0 master_port] == [lindex $addr 1]
   47     } else {
   48         fail "Old master not reconfigured as slave of new master"
   49     }
   50 }