test/system: Use port_is_free() from wait_for_port()

Currently, wait_for_port() duplicates the check logic implemented by
port_is_free().

Add an optional argument to port_is_free(), representing the bound
address to check, and call it, dropping the direct check in
wait_for_port().

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio
2022-10-03 23:49:20 +02:00
parent aa47e05ae4
commit 7e3d04fbc6

View File

@ -316,8 +316,10 @@ function random_free_port_range() {
}
function port_is_free() {
local port=${1?Usage: port_is_free PORT}
! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &>/dev/null
local port=${1?Usage: port_is_free PORT [ADDRESS]}
local address="${2:-127.0.0.1}"
! { exec {unused_fd}<> /dev/tcp/"${address}"/$port; } &>/dev/null
}
###################
@ -330,7 +332,7 @@ function wait_for_port() {
# Wait
while [ $_timeout -gt 0 ]; do
{ exec {unused_fd}<> /dev/tcp/$host/$port; } &>/dev/null && return
port_is_free ${port} "${host}" && return
sleep 1
_timeout=$(( $_timeout - 1 ))
done