diff --git a/test/system/505-networking-pasta.bats b/test/system/505-networking-pasta.bats index 1f41b61c1d..89f6b53534 100644 --- a/test/system/505-networking-pasta.bats +++ b/test/system/505-networking-pasta.bats @@ -211,34 +211,46 @@ function pasta_test_do() { local expect="$(for i in $(seq ${seq}); do printf "x"; done)" fi - # Set retry/initial delay for client to connect - local delay=1 - if [ ${ip_ver} -eq 6 ] && [ "${addr}" != "::1" ]; then - # Duplicate Address Detection on link-local - delay=3 - elif [ "${proto}" = "udp" ]; then - # With Podman up, and socat still starting, UDP clients send to nowhere - delay=2 - fi + # start server + local cname="c-socat-$(safename)" + run_podman run -d --name="$cname" --net=pasta"${pasta_spec}" -p "${podman_spec}" "${IMAGE}" \ + sh -c 'for port in $(seq '"${xseq}"'); do '\ +' socat -u '"${bind}"' '"${recv}"' & '\ +' done; wait' - # Now actually run the test: client, - for one_port in $(seq ${seq}); do - local connect="${proto_upper}${ip_ver}:[${addr}]:${one_port}" - [ "${proto}" = "udp" ] && connect="${connect},shut-null" + run_podman container inspect --format "{{.NetworkSettings.SandboxKey}}" $cname + netns="$output" + + # Make sure all ports in the contianer are bound + for cport in $(seq ${xseq}); do + retries=50 + while [[ $retries -gt 0 ]]; do + run_podman unshare nsenter -n"$netns" ss -Htuln -$ip_ver sport = $cport + if [[ $output =~ $cport ]]; then + break + fi + retries=$((retries - 1)) + sleep 0.1 + done + assert $retries -gt 0 "Timed out waiting for bount port $cport in container" + done - local retries=10 - (while sleep ${delay} && test $((retries--)) -gt 0 && ! timeout --foreground -v --kill=5 90 socat -u "OPEN:${XFER_FILE}" "${connect}"; do : - done) & + for hport in $(seq ${seq}); do + local connect="${proto_upper}${ip_ver}:[${addr}]:${hport}" + [ "${proto}" = "udp" ] && connect="${connect},shut-null" + # port is bound we can start the client in the background + timeout --foreground -v --kill=5 90 socat -u "OPEN:${XFER_FILE}" "${connect}" & done - # and server, - run_podman run --rm --name="c-socat-$(safename)" --net=pasta"${pasta_spec}" -p "${podman_spec}" "${IMAGE}" \ - sh -c 'for port in $(seq '"${xseq}"'); do '\ -' socat -u '"${bind}"' '"${recv}"' & '\ -' done; wait' + # Wait for the client childs to finish. + wait + # Get server output, --follow is used to wait for the container to exit, + run_podman logs --follow $cname # which should give us the expected output back. assert "${output}" = "${expect}" "Mismatch between data sent and received" + + run_podman rm $cname } ### Addresses ##################################################################