summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-07-20 05:04:35 -0400
committerGitHub <noreply@github.com>2021-07-20 05:04:35 -0400
commit36e47768e6b2b2a78b85535695aa9e7bb7f9c3a8 (patch)
tree4cf3da693bc55f14c900a68ac51c40052bdace0a
parentcea2f38e2160a62db122b8d9982e7ec1b5ac8de0 (diff)
parent80e807a1913411b6829a41ef47de285b38e27b66 (diff)
downloadpodman-36e47768e6b2b2a78b85535695aa9e7bb7f9c3a8.tar.gz
podman-36e47768e6b2b2a78b85535695aa9e7bb7f9c3a8.tar.bz2
podman-36e47768e6b2b2a78b85535695aa9e7bb7f9c3a8.zip
Merge pull request #10982 from cevich/fix_listen_flake
Flake Fix: Wait before connecting to container port
-rw-r--r--test/system/500-networking.bats2
-rw-r--r--test/system/helpers.bash18
2 files changed, 20 insertions, 0 deletions
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index 4feb57807..419d325b0 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -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
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 1859a2168..02fd7252c 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -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