From 63ae18c3de280ea0ff90701e0f126437cbbce36c Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:31:39 -0600 Subject: [PATCH] test(tls): wait for the loopback listener with Awaitility (#10175) Use the existing bounded socket probe to poll the IPv4 listener. Keep the startup deadline and include the port in a timeout. Signed-off-by: Andre Kurait Signed-off-by: Jackson Price Co-authored-by: Andre Kurait --- .../io/floci/aws/config/TlsProxyServerTest.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/test/java/io/floci/aws/config/TlsProxyServerTest.java b/src/test/java/io/floci/aws/config/TlsProxyServerTest.java index 436d4501a0..8eddaf8845 100644 --- a/src/test/java/io/floci/aws/config/TlsProxyServerTest.java +++ b/src/test/java/io/floci/aws/config/TlsProxyServerTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -454,16 +455,12 @@ class TlsProxyServerTest { } } - private void awaitListening(int port) throws Exception { - long deadline = System.currentTimeMillis() + 10_000; - while (System.currentTimeMillis() < deadline) { - try (Socket s = new Socket("127.0.0.1", port)) { - return; - } catch (IOException e) { - Thread.sleep(50); - } - } - fail("port " + port + " not listening within timeout"); + private void awaitListening(int port) { + InetAddress loopback = InetAddress.ofLiteral("127.0.0.1"); + await("TLS proxy on 127.0.0.1:" + port) + .pollInterval(50, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS) + .until(() -> accepts(loopback, port)); } private static boolean accepts(InetAddress address, int port) {