mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #10982 from cevich/fix_listen_flake
Flake Fix: Wait before connecting to container port
This commit is contained in:
@ -139,6 +139,8 @@ load helpers
|
|||||||
$IMAGE nc -l -n -v -p $myport
|
$IMAGE nc -l -n -v -p $myport
|
||||||
cid="$output"
|
cid="$output"
|
||||||
|
|
||||||
|
wait_for_port 127.0.0.1 $myport
|
||||||
|
|
||||||
# emit random string, and check it
|
# emit random string, and check it
|
||||||
teststring=$(random_string 30)
|
teststring=$(random_string 30)
|
||||||
echo "$teststring" | nc 127.0.0.1 $myport
|
echo "$teststring" | nc 127.0.0.1 $myport
|
||||||
|
@ -278,6 +278,24 @@ function wait_for_ready {
|
|||||||
wait_for_output '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
|
# END podman helpers
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# BEGIN miscellaneous tools
|
# BEGIN miscellaneous tools
|
||||||
|
Reference in New Issue
Block a user