Merge pull request #10982 from cevich/fix_listen_flake

Flake Fix: Wait before connecting to container port
This commit is contained in:
OpenShift Merge Robot
2021-07-20 05:04:35 -04:00
committed by GitHub
2 changed files with 20 additions and 0 deletions

View File

@ -139,6 +139,8 @@ load helpers
$IMAGE nc -l -n -v -p $myport
cid="$output"
wait_for_port 127.0.0.1 $myport
# emit random string, and check it
teststring=$(random_string 30)
echo "$teststring" | nc 127.0.0.1 $myport

View File

@ -278,6 +278,24 @@ function wait_for_ready {
wait_for_output 'READY' "$@"
}
###################
# wait_for_port # Returns once port is available on host
###################
function wait_for_port() {
local host=$1 # Probably "localhost"
local port=$2 # Numeric port
local _timeout=${3:-5} # Optional; default to 5 seconds
# Wait
while [ $_timeout -gt 0 ]; do
{ exec 3<> /dev/tcp/$host/$port; } &>/dev/null && return
sleep 1
_timeout=$(( $_timeout - 1 ))
done
die "Timed out waiting for $host:$port"
}
# END podman helpers
###############################################################################
# BEGIN miscellaneous tools