From 7e3d04fbc6de0da3d39217070530dc522ee7c282 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 3 Oct 2022 23:49:20 +0200 Subject: [PATCH] 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 --- test/system/helpers.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/system/helpers.bash b/test/system/helpers.bash index 3f9d0f48dd..bc78a51040 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -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