"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/07-down-conditions.tcl" (21 Sep 2022, 3330 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 conditions where an instance is considered to be down
    2 
    3 source "../tests/includes/init-tests.tcl"
    4 source "../../../tests/support/cli.tcl"
    5 
    6 foreach_sentinel_id id {
    7     S $id sentinel debug info-period 1000
    8     S $id sentinel debug ask-period 100
    9     S $id sentinel debug default-down-after 3000
   10     S $id sentinel debug publish-period 200
   11     S $id sentinel debug ping-period 100
   12 }
   13 
   14 set ::alive_sentinel [expr {$::instances_count/2+2}]
   15 proc ensure_master_up {} {
   16     S $::alive_sentinel sentinel debug info-period 1000
   17     S $::alive_sentinel sentinel debug ping-period 100
   18     S $::alive_sentinel sentinel debug ask-period 100
   19     S $::alive_sentinel sentinel debug publish-period 100
   20     wait_for_condition 1000 50 {
   21         [dict get [S $::alive_sentinel sentinel master mymaster] flags] eq "master"
   22     } else {
   23         fail "Master flags are not just 'master'"
   24     }
   25 }
   26 
   27 proc ensure_master_down {} {
   28     S $::alive_sentinel sentinel debug info-period 1000
   29     S $::alive_sentinel sentinel debug ping-period 100
   30     S $::alive_sentinel sentinel debug ask-period 100
   31     S $::alive_sentinel sentinel debug publish-period 100
   32     wait_for_condition 1000 50 {
   33         [string match *down* \
   34             [dict get [S $::alive_sentinel sentinel master mymaster] flags]]
   35     } else {
   36         fail "Master is not flagged SDOWN"
   37     }
   38 }
   39 
   40 test "Crash the majority of Sentinels to prevent failovers for this unit" {
   41     for {set id 0} {$id < $quorum} {incr id} {
   42         kill_instance sentinel $id
   43     }
   44 }
   45 
   46 test "SDOWN is triggered by non-responding but not crashed instance" {
   47     ensure_master_up
   48     set master_addr [S $::alive_sentinel SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
   49     set master_id [get_instance_id_by_port redis [lindex $master_addr 1]]
   50 
   51     set pid [get_instance_attrib redis $master_id pid]
   52     exec kill -SIGSTOP $pid
   53     ensure_master_down
   54     exec kill -SIGCONT $pid
   55     ensure_master_up
   56 }
   57 
   58 test "SDOWN is triggered by crashed instance" {
   59     lassign [S $::alive_sentinel SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] host port
   60     ensure_master_up
   61     kill_instance redis 0
   62     ensure_master_down
   63     restart_instance redis 0
   64     ensure_master_up
   65 }
   66 
   67 test "SDOWN is triggered by masters advertising as slaves" {
   68     ensure_master_up
   69     R 0 slaveof 127.0.0.1 34567
   70     ensure_master_down
   71     R 0 slaveof no one
   72     ensure_master_up
   73 }
   74 
   75 test "SDOWN is triggered by misconfigured instance replying with errors" {
   76     ensure_master_up
   77     set orig_dir [lindex [R 0 config get dir] 1]
   78     set orig_save [lindex [R 0 config get save] 1]
   79     # Set dir to / and filename to "tmp" to make sure it will fail.
   80     R 0 config set dir /
   81     R 0 config set dbfilename tmp
   82     R 0 config set save "1000000 1000000"
   83     after 5000
   84     R 0 bgsave
   85     after 5000
   86     ensure_master_down
   87     R 0 config set save $orig_save
   88     R 0 config set dir $orig_dir
   89     R 0 config set dbfilename dump.rdb
   90     R 0 bgsave
   91     ensure_master_up
   92 }
   93 
   94 # We use this test setup to also test command renaming, as a side
   95 # effect of the master going down if we send PONG instead of PING
   96 test "SDOWN is triggered if we rename PING to PONG" {
   97     ensure_master_up
   98     S $::alive_sentinel SENTINEL SET mymaster rename-command PING PONG
   99     ensure_master_down
  100     S $::alive_sentinel SENTINEL SET mymaster rename-command PING PING
  101     ensure_master_up
  102 }