tests: each test client work on a distinct port range
apparently when running tests in parallel (the default of --clients 16), there's a chance for two tests to use the same port. specifically, one test might shutdown a master and still have the replica up, and then another test will re-use the port number of master for another master, and then that replica will connect to the master of the other test. this can cause a master to count too many full syncs and fail a test if we run the tests with --single integration/psync2 --loop --stop see Probmem 2 in #7314
This commit is contained in:
+10
-11
@@ -214,14 +214,14 @@ proc start_server {options {code undefined}} {
|
||||
dict set config dir [tmpdir server]
|
||||
|
||||
# start every server on a different port
|
||||
set ::port [find_available_port [expr {$::port+1}]]
|
||||
set port [find_available_port $::baseport $::portcount]
|
||||
if {$::tls} {
|
||||
dict set config "port" 0
|
||||
dict set config "tls-port" $::port
|
||||
dict set config "tls-port" $port
|
||||
dict set config "tls-cluster" "yes"
|
||||
dict set config "tls-replication" "yes"
|
||||
} else {
|
||||
dict set config port $::port
|
||||
dict set config port $port
|
||||
}
|
||||
|
||||
set unixsocket [file normalize [format "%s/%s" [dict get $config "dir"] "socket"]]
|
||||
@@ -243,10 +243,10 @@ proc start_server {options {code undefined}} {
|
||||
set server_started 0
|
||||
while {$server_started == 0} {
|
||||
if {$::verbose} {
|
||||
puts -nonewline "=== ($tags) Starting server ${::host}:${::port} "
|
||||
puts -nonewline "=== ($tags) Starting server ${::host}:${port} "
|
||||
}
|
||||
|
||||
send_data_packet $::test_server_fd "server-spawning" "port $::port"
|
||||
send_data_packet $::test_server_fd "server-spawning" "port $port"
|
||||
|
||||
if {$::valgrind} {
|
||||
set pid [exec valgrind --track-origins=yes --suppressions=src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full src/redis-server $config_file > $stdout 2> $stderr &]
|
||||
@@ -291,19 +291,19 @@ proc start_server {options {code undefined}} {
|
||||
# for availability. Other test clients may grab the port before we
|
||||
# are able to do it for example.
|
||||
if {$port_busy} {
|
||||
puts "Port $::port was already busy, trying another port..."
|
||||
set ::port [find_available_port [expr {$::port+1}]]
|
||||
puts "Port $port was already busy, trying another port..."
|
||||
set port [find_available_port $::baseport $::portcount]
|
||||
if {$::tls} {
|
||||
dict set config "tls-port" $::port
|
||||
dict set config "tls-port" $port
|
||||
} else {
|
||||
dict set config port $::port
|
||||
dict set config port $port
|
||||
}
|
||||
create_server_config_file $config_file $config
|
||||
continue; # Try again
|
||||
}
|
||||
|
||||
if {$code ne "undefined"} {
|
||||
set serverisup [server_is_up $::host $::port $retrynum]
|
||||
set serverisup [server_is_up $::host $port $retrynum]
|
||||
} else {
|
||||
set serverisup 1
|
||||
}
|
||||
@@ -324,7 +324,6 @@ proc start_server {options {code undefined}} {
|
||||
# setup properties to be able to initialize a client object
|
||||
set port_param [expr $::tls ? {"tls-port"} : {"port"}]
|
||||
set host $::host
|
||||
set port $::port
|
||||
if {[dict exists $config bind]} { set host [dict get $config bind] }
|
||||
if {[dict exists $config $port_param]} { set port [dict get $config $port_param] }
|
||||
|
||||
|
||||
@@ -344,8 +344,8 @@ proc roundFloat f {
|
||||
format "%.10g" $f
|
||||
}
|
||||
|
||||
proc find_available_port start {
|
||||
for {set j $start} {$j < $start+1024} {incr j} {
|
||||
proc find_available_port {start count} {
|
||||
for {set j $start} {$j < $start+$count} {incr j} {
|
||||
if {[catch {set fd1 [socket 127.0.0.1 $j]}] &&
|
||||
[catch {set fd2 [socket 127.0.0.1 [expr $j+10000]]}]} {
|
||||
return $j
|
||||
@@ -356,8 +356,8 @@ proc find_available_port start {
|
||||
}
|
||||
}
|
||||
}
|
||||
if {$j == $start+1024} {
|
||||
error "Can't find a non busy port in the $start-[expr {$start+1023}] range."
|
||||
if {$j == $start+$count} {
|
||||
error "Can't find a non busy port in the $start-[expr {$start+$count-1}] range."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user