From c841fa9e9a66114e22756c966b7957e07d4c3cff Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Thu, 26 Oct 2023 05:47:44 -0600 Subject: [PATCH] CI: e2e: safer GetPort() Problem: frequent CI flakes of the form: Error: cannot listen on the TCP port: listen tcp4 :5355: bind: address already in use Always 5355. Cause: systemd-resolve listens on 5355, but not on 127.0.0.1. So when GetPort() tries its is-it-in-use check by binding localhost, it succeeds; but then podman binds * and fails. Solution: GetPort(): test by binding 0.0.0.0. Also, improve the failure message. Signed-off-by: Ed Santiago --- test/e2e/common_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 021bd1d25f..54236c8541 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -1233,7 +1233,7 @@ func GetPort() int { // Random port within that range port := portMin + rng.Intn((portMax-portMin)/nProcs)*nProcs + myProc - used, err := net.Listen("tcp", "localhost:"+strconv.Itoa(port)) + used, err := net.Listen("tcp", "0.0.0.0:"+strconv.Itoa(port)) if err == nil { // it's open. Return it. err = used.Close() @@ -1242,7 +1242,7 @@ func GetPort() int { } } - Fail(fmt.Sprintf("unable to get free port: %v", err)) + Fail(fmt.Sprintf("unable to get free port in range %d-%d", portMin, portMax)) return 0 // notreached }