Skip to content

Commit

Permalink
test/system: Use port_is_free() from wait_for_port()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sbrivio-rh committed Nov 7, 2022
1 parent aa47e05 commit 7e3d04f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/system/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

###################
Expand All @@ -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
Expand Down

0 comments on commit 7e3d04f

Please sign in to comment.