"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/12-master-reboot.tcl" (21 Sep 2022, 3125 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 the basic monitoring and failover capabilities.
    2 source "../tests/includes/init-tests.tcl"
    3 
    4 
    5 if {$::simulate_error} {
    6     test "This test will fail" {
    7         fail "Simulated error"
    8     }
    9 }
   10 
   11 
   12 # Reboot an instance previously in very short time but do not check if it is loading
   13 proc reboot_instance {type id} {
   14     set dirname "${type}_${id}"
   15     set cfgfile [file join $dirname $type.conf]
   16     set port [get_instance_attrib $type $id port]
   17 
   18     # Execute the instance with its old setup and append the new pid
   19     # file for cleanup.
   20     set pid [exec_instance $type $dirname $cfgfile]
   21     set_instance_attrib $type $id pid $pid
   22     lappend ::pids $pid
   23 
   24     # Check that the instance is running
   25     if {[server_is_up 127.0.0.1 $port 100] == 0} {
   26         set logfile [file join $dirname log.txt]
   27         puts [exec tail $logfile]
   28         abort_sentinel_test "Problems starting $type #$id: ping timeout, maybe server start failed, check $logfile"
   29     }
   30 
   31     # Connect with it with a fresh link
   32     set link [redis 127.0.0.1 $port 0 $::tls]
   33     $link reconnect 1
   34     set_instance_attrib $type $id link $link
   35 }
   36 
   37 
   38 test "Master reboot in very short time" {
   39     set old_port [RPort $master_id]
   40     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   41     assert {[lindex $addr 1] == $old_port}
   42     
   43     R $master_id debug populate 10000
   44     R $master_id bgsave
   45     R $master_id config set key-load-delay 1500
   46     R $master_id config set loading-process-events-interval-bytes 1024
   47     R $master_id config rewrite
   48 
   49     foreach_sentinel_id id {
   50         S $id SENTINEL SET mymaster master-reboot-down-after-period 5000
   51         S $id sentinel debug ping-period 500
   52         S $id sentinel debug ask-period 500 
   53     }
   54 
   55     kill_instance redis $master_id
   56     reboot_instance redis $master_id
   57     
   58     foreach_sentinel_id id {        
   59         wait_for_condition 1000 100 {
   60             [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
   61         } else {
   62             fail "At least one Sentinel did not receive failover info"
   63         }
   64     }
   65 
   66     set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   67     set master_id [get_instance_id_by_port redis [lindex $addr 1]]
   68 
   69     # Make sure the instance load all the dataset
   70     while 1 {
   71         catch {[$link ping]} retval
   72         if {[string match {*LOADING*} $retval]} {
   73             after 100
   74             continue
   75         } else {
   76             break
   77         }
   78     }
   79 }
   80 
   81 test "New master [join $addr {:}] role matches" {
   82     assert {[RI $master_id role] eq {master}}
   83 }
   84 
   85 test "All the other slaves now point to the new master" {
   86     foreach_redis_id id {
   87         if {$id != $master_id && $id != 0} {
   88             wait_for_condition 1000 50 {
   89                 [RI $id master_port] == [lindex $addr 1]
   90             } else {
   91                 fail "Redis ID $id not configured to replicate with new master"
   92             }
   93         }
   94     }
   95 }
   96 
   97 test "The old master eventually gets reconfigured as a slave" {
   98     wait_for_condition 1000 50 {
   99         [RI 0 master_port] == [lindex $addr 1]
  100     } else {
  101         fail "Old master not reconfigured as slave of new master"
  102     }
  103 }