Skip to content

Commit 7dfedfe

Browse files
committed
test(net): make black-hole connect-timeout test CI-routing-robust
On a runner with no route to TEST-NET-1 (192.0.2.0/24) connect() fails fast with ENETUNREACH instead of dropping the SYN, so the timeout path can't be exercised. Skip (Assume) in that case rather than asserting a timeout, while still proving the call never blocked on the OS connect timeout.
1 parent 23a9824 commit 7dfedfe

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

core/src/test/java/io/questdb/client/test/network/NetConnectTimeoutTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.questdb.client.network.NetworkFacade;
2828
import io.questdb.client.network.NetworkFacadeImpl;
2929
import org.junit.Assert;
30+
import org.junit.Assume;
3031
import org.junit.Test;
3132

3233
import java.net.InetSocketAddress;
@@ -95,13 +96,20 @@ public void testConnectToBlackholeTimesOut() {
9596
long start = System.nanoTime();
9697
int rc = NF.connectAddrInfoTimeout(fd, addrInfo, 500);
9798
long elapsedMs = (System.nanoTime() - start) / 1_000_000L;
98-
if (rc == 0) {
99-
// Extremely unusual: some network appliance accepted the SYN.
100-
// Don't fail the build on a hostile network; just skip.
101-
return;
102-
}
99+
100+
// Whatever the outcome, the key guarantee is that we never blocked
101+
// on the (multi-minute) OS connect timeout.
102+
Assert.assertTrue("connect must return near the budget, was " + elapsedMs + "ms", elapsedMs < 5_000);
103+
104+
// The deterministic outcome depends on the runner's routing for
105+
// TEST-NET-1: a dropped SYN yields a real timeout (the path under
106+
// test), while a runner with no route to 192.0.2.0/24 fails fast
107+
// with ENETUNREACH/EHOSTUNREACH (rc == -1) and a rare appliance may
108+
// even accept it (rc == 0). Only the timeout case is assertable; the
109+
// others can't exercise the timeout, so skip rather than flake.
110+
Assume.assumeTrue("no route to blackhole on this runner (rc=" + rc + ")",
111+
rc == NetworkFacade.CONNECT_TIMEOUT);
103112
Assert.assertEquals("blackhole connect should time out", NetworkFacade.CONNECT_TIMEOUT, rc);
104-
Assert.assertTrue("timeout should fire near the budget, was " + elapsedMs + "ms", elapsedMs < 5_000);
105113
} finally {
106114
NF.freeAddrInfo(addrInfo);
107115
NF.close(fd);

0 commit comments

Comments
 (0)