Unverified Commit 92e80047 authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Pre-test bind-source-addr before running test. (#9214)

This attempts to catch any non-standard configuration where the test may
fail and produce a false positive.
parent 350c6306
......@@ -37,8 +37,40 @@ test {CONFIG SET bind address} {
}
} {} {external:skip}
# Attempt to connect to host using a client bound to bindaddr,
# and return a non-zero value if successful within specified
# millisecond timeout, or zero otherwise.
proc test_loopback {host bindaddr timeout} {
if {[exec uname] != {Linux}} {
return 0
}
after $timeout set ::test_loopback_state timeout
if {[catch {
set server_sock [socket -server accept 0]
set port [lindex [fconfigure $server_sock -sockname] 2] } err]} {
return 0
}
proc accept {channel clientaddr clientport} {
set ::test_loopback_state "connected"
close $channel
}
if {[catch {set client_sock [socket -async -myaddr $bindaddr $host $port]} err]} {
puts "test_loopback: Client connect failed: $err"
} else {
close $client_sock
}
vwait ::test_loopback_state
close $server_sock
return [expr {$::test_loopback_state == {connected}}]
}
test {CONFIG SET bind-source-addr} {
if {[exec uname] == {Linux}} {
if {[test_loopback 127.0.0.1 127.0.0.2 1000]} {
start_server {} {
start_server {} {
set replica [srv 0 client]
......@@ -58,6 +90,8 @@ test {CONFIG SET bind-source-addr} {
assert_match {*ip=127.0.0.2*} [s -1 slave0]
}
}
} else {
if {$::verbose} { puts "Skipping bind-source-addr test." }
}
} {} {external:skip}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment