From eacccd2acbbebde3e50e14a4d0ade5b1ccc2bc07 Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Sat, 30 Jan 2021 04:18:58 -0500 Subject: [PATCH] fix sentinel tests error (#8422) This commit fixes sentinel announces hostnames test error in certain linux environment Before this commit, we only check localhost is resolved into 127.0.0.1, however in ubuntu or some other linux environments "localhost" will be resolved into ::1 ipv6 address first if the network stack is capable. --- tests/sentinel/tests/08-hostname-conf.tcl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/sentinel/tests/08-hostname-conf.tcl b/tests/sentinel/tests/08-hostname-conf.tcl index 45bb56687..be6e42cb0 100644 --- a/tests/sentinel/tests/08-hostname-conf.tcl +++ b/tests/sentinel/tests/08-hostname-conf.tcl @@ -33,13 +33,18 @@ source "../tests/includes/init-tests.tcl" proc verify_hostname_announced {hostname} { foreach_sentinel_id id { # Master is reported with its hostname - assert_equal [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 0] $hostname + if {![string equal [lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 0] $hostname]} { + return 0 + } # Replicas are reported with their hostnames foreach replica [S $id SENTINEL REPLICAS mymaster] { - assert_equal [dict get $replica ip] $hostname + if {![string equal [dict get $replica ip] $hostname]} { + return 0 + } } } + return 1 } test "Sentinel announces hostnames" { @@ -48,7 +53,7 @@ test "Sentinel announces hostnames" { # Disable announce-hostnames and confirm IPs are used set_sentinel_config announce-hostnames no - verify_hostname_announced "127.0.0.1" + assert {[verify_hostname_announced "127.0.0.1"] || [verify_hostname_announced "::1"]} } # We need to revert any special configuration because all tests currently