"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/sentinel/tests/08-hostname-conf.tcl" (21 Sep 2022, 2019 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 source "../tests/includes/utils.tcl"
    2 
    3 proc set_redis_announce_ip {addr} {
    4     foreach_redis_id id {
    5         R $id config set replica-announce-ip $addr
    6     }
    7 }
    8 
    9 proc set_sentinel_config {keyword value} {
   10     foreach_sentinel_id id {
   11         S $id sentinel config set $keyword $value
   12     }
   13 }
   14 
   15 proc set_all_instances_hostname {hostname} {
   16     foreach_sentinel_id id {
   17         set_instance_attrib sentinel $id host $hostname
   18     }
   19     foreach_redis_id id {
   20         set_instance_attrib redis $id host $hostname
   21     }
   22 }
   23 
   24 test "(pre-init) Configure instances and sentinel for hostname use" {
   25     set ::host "localhost"
   26     restart_killed_instances
   27     set_all_instances_hostname $::host
   28     set_redis_announce_ip $::host
   29     set_sentinel_config resolve-hostnames yes
   30     set_sentinel_config announce-hostnames yes
   31 }
   32 
   33 source "../tests/includes/init-tests.tcl"
   34 
   35 proc verify_hostname_announced {hostname} {
   36     foreach_sentinel_id id {
   37         # Master is reported with its hostname
   38         if {![string equal [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 0] $hostname]} {
   39             return 0
   40         }
   41 
   42         # Replicas are reported with their hostnames
   43         foreach replica [S $id SENTINEL REPLICAS mymaster] {
   44             if {![string equal [dict get $replica ip] $hostname]} {
   45                 return 0
   46             }
   47         }
   48     }
   49     return 1
   50 }
   51 
   52 test "Sentinel announces hostnames" {
   53     # Check initial state
   54     verify_hostname_announced $::host
   55 
   56     # Disable announce-hostnames and confirm IPs are used
   57     set_sentinel_config announce-hostnames no
   58     assert {[verify_hostname_announced "127.0.0.1"] || [verify_hostname_announced "::1"]}
   59 }
   60 
   61 # We need to revert any special configuration because all tests currently
   62 # share the same instances.
   63 test "(post-cleanup) Configure instances and sentinel for IPs" {
   64     set ::host "127.0.0.1"
   65     set_all_instances_hostname $::host
   66     set_redis_announce_ip $::host
   67     set_sentinel_config resolve-hostnames no
   68     set_sentinel_config announce-hostnames no
   69 }