"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/00-base.tcl" (21 Sep 2022, 4311 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. See also the last Fossies "Diffs" side-by-side code changes report for "00-base.tcl": 7.0.2_vs_7.0.3.

    1 # Check the basic monitoring and failover capabilities.
    2 source "../tests/includes/start-init-tests.tcl"
    3 source "../tests/includes/init-tests.tcl"
    4 
    5 foreach_sentinel_id id {
    6     S $id sentinel debug default-down-after 1000
    7 }
    8 
    9 if {$::simulate_error} {
   10     test "This test will fail" {
   11         fail "Simulated error"
   12     }
   13 }
   14 
   15 test "Sentinel commands sanity check" {
   16     foreach_sentinel_id id {
   17         assert_equal {72} [llength [S $id command list]]
   18         assert_equal {15} [S $id command count]
   19     }
   20 }
   21 
   22 test "Basic failover works if the master is down" {
   23     set old_port [RPort $master_id]
   24     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   25     assert {[lindex $addr 1] == $old_port}
   26     kill_instance redis $master_id
   27     foreach_sentinel_id id {
   28         S $id sentinel debug ping-period 500
   29         S $id sentinel debug ask-period 500  
   30         wait_for_condition 1000 100 {
   31             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
   32         } else {
   33             fail "At least one Sentinel did not receive failover info"
   34         }
   35     }
   36     restart_instance redis $master_id
   37     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   38     set master_id [get_instance_id_by_port redis [lindex $addr 1]]
   39 }
   40 
   41 test "New master [join $addr {:}] role matches" {
   42     assert {[RI $master_id role] eq {master}}
   43 }
   44 
   45 test "All the other slaves now point to the new master" {
   46     foreach_redis_id id {
   47         if {$id != $master_id && $id != 0} {
   48             wait_for_condition 1000 50 {
   49                 [RI $id master_port] == [lindex $addr 1]
   50             } else {
   51                 fail "Redis ID $id not configured to replicate with new master"
   52             }
   53         }
   54     }
   55 }
   56 
   57 test "The old master eventually gets reconfigured as a slave" {
   58     wait_for_condition 1000 50 {
   59         [RI 0 master_port] == [lindex $addr 1]
   60     } else {
   61         fail "Old master not reconfigured as slave of new master"
   62     }
   63 }
   64 
   65 test "ODOWN is not possible without N (quorum) Sentinels reports" {
   66     foreach_sentinel_id id {
   67         S $id SENTINEL SET mymaster quorum [expr $sentinels+1]
   68     }
   69     set old_port [RPort $master_id]
   70     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   71     assert {[lindex $addr 1] == $old_port}
   72     kill_instance redis $master_id
   73 
   74     # Make sure failover did not happened.
   75     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   76     assert {[lindex $addr 1] == $old_port}
   77     restart_instance redis $master_id
   78 }
   79 
   80 test "Failover is not possible without majority agreement" {
   81     foreach_sentinel_id id {
   82         S $id SENTINEL SET mymaster quorum $quorum
   83     }
   84 
   85     # Crash majority of sentinels
   86     for {set id 0} {$id < $quorum} {incr id} {
   87         kill_instance sentinel $id
   88     }
   89 
   90     # Kill the current master
   91     kill_instance redis $master_id
   92 
   93     # Make sure failover did not happened.
   94     set addr [S $quorum SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   95     assert {[lindex $addr 1] == $old_port}
   96     restart_instance redis $master_id
   97 
   98     # Cleanup: restart Sentinels to monitor the master.
   99     for {set id 0} {$id < $quorum} {incr id} {
  100         restart_instance sentinel $id
  101     }
  102 }
  103 
  104 test "Failover works if we configure for absolute agreement" {
  105     foreach_sentinel_id id {
  106         S $id SENTINEL SET mymaster quorum $sentinels
  107     }
  108 
  109     # Wait for Sentinels to monitor the master again
  110     foreach_sentinel_id id {
  111         wait_for_condition 1000 100 {
  112             [dict get [S $id SENTINEL MASTER mymaster] info-refresh] < 100000
  113         } else {
  114             fail "At least one Sentinel is not monitoring the master"
  115         }
  116     }
  117 
  118     kill_instance redis $master_id
  119 
  120     foreach_sentinel_id id {
  121         wait_for_condition 1000 100 {
  122             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
  123         } else {
  124             fail "At least one Sentinel did not receive failover info"
  125         }
  126     }
  127     restart_instance redis $master_id
  128     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
  129     set master_id [get_instance_id_by_port redis [lindex $addr 1]]
  130 
  131     # Set the min ODOWN agreement back to strict majority.
  132     foreach_sentinel_id id {
  133         S $id SENTINEL SET mymaster quorum $quorum
  134     }
  135 }
  136 
  137 test "New master [join $addr {:}] role matches" {
  138     assert {[RI $master_id role] eq {master}}
  139 }