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 <akurait@amazon.com>
Signed-off-by: Jackson Price <jxnprice@amazon.com>
Co-authored-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Jackson PriceandAndre Kurait authored and GitHub committed 2026-12-04 15:31:39 -04:00
1 parent cf50025eaa
commit 63ae18c3de
1 file changed
+7 -10
@@ -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) {