"Fossies" - the Fresh Open Source Software Archive

Member "redis-5.0.6/tests/sentinel/tests/00-base.tcl" (25 Sep 2019, 3922 Bytes) of package /linux/misc/redis-5.0.6.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 and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # Check the basic monitoring and failover capabilities.
    2 
    3 source "../tests/includes/init-tests.tcl"
    4 
    5 if {$::simulate_error} {
    6     test "This test will fail" {
    7         fail "Simulated error"
    8     }
    9 }
   10 
   11 test "Basic failover works if the master is down" {
   12     set old_port [RI $master_id tcp_port]
   13     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   14     assert {[lindex $addr 1] == $old_port}
   15     kill_instance redis $master_id
   16     foreach_sentinel_id id {
   17         wait_for_condition 1000 50 {
   18             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
   19         } else {
   20             fail "At least one Sentinel did not receive failover info"
   21         }
   22     }
   23     restart_instance redis $master_id
   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 }
   51 
   52 test "ODOWN is not possible without N (quorum) Sentinels reports" {
   53     foreach_sentinel_id id {
   54         S $id SENTINEL SET mymaster quorum [expr $sentinels+1]
   55     }
   56     set old_port [RI $master_id tcp_port]
   57     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   58     assert {[lindex $addr 1] == $old_port}
   59     kill_instance redis $master_id
   60 
   61     # Make sure failover did not happened.
   62     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   63     assert {[lindex $addr 1] == $old_port}
   64     restart_instance redis $master_id
   65 }
   66 
   67 test "Failover is not possible without majority agreement" {
   68     foreach_sentinel_id id {
   69         S $id SENTINEL SET mymaster quorum $quorum
   70     }
   71 
   72     # Crash majority of sentinels
   73     for {set id 0} {$id < $quorum} {incr id} {
   74         kill_instance sentinel $id
   75     }
   76 
   77     # Kill the current master
   78     kill_instance redis $master_id
   79 
   80     # Make sure failover did not happened.
   81     set addr [S $quorum SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   82     assert {[lindex $addr 1] == $old_port}
   83     restart_instance redis $master_id
   84 
   85     # Cleanup: restart Sentinels to monitor the master.
   86     for {set id 0} {$id < $quorum} {incr id} {
   87         restart_instance sentinel $id
   88     }
   89 }
   90 
   91 test "Failover works if we configure for absolute agreement" {
   92     foreach_sentinel_id id {
   93         S $id SENTINEL SET mymaster quorum $sentinels
   94     }
   95 
   96     # Wait for Sentinels to monitor the master again
   97     foreach_sentinel_id id {
   98         wait_for_condition 1000 50 {
   99             [dict get [S $id SENTINEL MASTER mymaster] info-refresh] < 100000
  100         } else {
  101             fail "At least one Sentinel is not monitoring the master"
  102         }
  103     }
  104 
  105     kill_instance redis $master_id
  106 
  107     foreach_sentinel_id id {
  108         wait_for_condition 1000 50 {
  109             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
  110         } else {
  111             fail "At least one Sentinel did not receive failover info"
  112         }
  113     }
  114     restart_instance redis $master_id
  115     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
  116     set master_id [get_instance_id_by_port redis [lindex $addr 1]]
  117 
  118     # Set the min ODOWN agreement back to strict majority.
  119     foreach_sentinel_id id {
  120         S $id SENTINEL SET mymaster quorum $quorum
  121     }
  122 }
  123 
  124 test "New master [join $addr {:}] role matches" {
  125     assert {[RI $master_id role] eq {master}}
  126 }