Skip to content

Commit

Permalink
test/system: Add, use tcp_port_probe() to check for listeners rather …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
sbrivio-rh committed Nov 7, 2022
1 parent 348c3f2 commit cb8c9af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/system/150-login.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions test/system/helpers.network.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

0 comments on commit cb8c9af

Please sign in to comment.