From cb8c9af5d3d49f34241bcdf5390c56d7e2048ad1 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 17 Oct 2022 21:19:54 +0200 Subject: [PATCH] test/system: Add, use tcp_port_probe() to check for listeners rather than binds _test_skopeo_credential_sharing() used port_is_free() to check if a port has no active listeners. With the new implementation, this is not equivalent anymore: a port might be in TIME_WAIT, so it's not free, but the listener might be long gone. Add tcp_port_probe() to check if there's an active listener on a given port, and use it in _test_skopeo_credential_sharing(). Signed-off-by: Stefano Brivio --- test/system/150-login.bats | 2 +- test/system/helpers.network.bash | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/system/150-login.bats b/test/system/150-login.bats index 7851ee0448..95d1c8bb2f 100644 --- a/test/system/150-login.bats +++ b/test/system/150-login.bats @@ -344,7 +344,7 @@ function _test_skopeo_credential_sharing() { fi # Make sure socket is closed - if ! port_is_free $PODMAN_LOGIN_REGISTRY_PORT; then + if tcp_port_probe $PODMAN_LOGIN_REGISTRY_PORT; then die "Socket still seems open" fi } diff --git a/test/system/helpers.network.bash b/test/system/helpers.network.bash index 52927b8c72..a88db0c615 100644 --- a/test/system/helpers.network.bash +++ b/test/system/helpers.network.bash @@ -286,3 +286,12 @@ function wait_for_port() { die "Timed out waiting for $host:$port" } + +# tcp_port_probe() - Check if a TCP port has an active listener +# $1: Port number +# $2: Optional address, 0.0.0.0 by default +function tcp_port_probe() { + local address="${2:-0.0.0.0}" + + : | nc "${address}" "${1}" +}