summaryrefslogtreecommitdiff
path: root/test/system/helpers.bash
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-09-08 10:57:24 -0600
committerEd Santiago <santiago@redhat.com>2021-09-08 11:25:42 -0600
commit1ff797e3621e7e370f53c4c71c9f40bb6a878936 (patch)
tree0e39a0e3ba4348e05b157253d042b4366f7dc74d /test/system/helpers.bash
parentd68e429859b497cd31c6e3dfdc64dce58b0b95d5 (diff)
downloadpodman-1ff797e3621e7e370f53c4c71c9f40bb6a878936.tar.gz
podman-1ff797e3621e7e370f53c4c71c9f40bb6a878936.tar.bz2
podman-1ff797e3621e7e370f53c4c71c9f40bb6a878936.zip
system tests: new random_free_port helper
Picks a pseudorandom open port within a range. Refactor existing instances of such code. Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/system/helpers.bash')
-rw-r--r--test/system/helpers.bash19
1 files changed, 18 insertions, 1 deletions
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index bd9471ace..28ea924bb 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -278,6 +278,23 @@ function wait_for_ready {
wait_for_output 'READY' "$@"
}
+######################
+# random_free_port # Pick an available port within a specified range
+######################
+function random_free_port() {
+ local range=${1:-5000-5999}
+
+ local port
+ for port in $(shuf -i ${range}); do
+ if ! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
+ echo $port
+ return
+ fi
+ done
+
+ die "Could not find open port in range $range"
+}
+
###################
# wait_for_port # Returns once port is available on host
###################
@@ -288,7 +305,7 @@ function wait_for_port() {
# Wait
while [ $_timeout -gt 0 ]; do
- { exec 5<> /dev/tcp/$host/$port; } &>/dev/null && return
+ { exec {unused_fd}<> /dev/tcp/$host/$port; } &>/dev/null && return
sleep 1
_timeout=$(( $_timeout - 1 ))
done