|
27 | 27 | import io.questdb.client.network.NetworkFacade; |
28 | 28 | import io.questdb.client.network.NetworkFacadeImpl; |
29 | 29 | import org.junit.Assert; |
| 30 | +import org.junit.Assume; |
30 | 31 | import org.junit.Test; |
31 | 32 |
|
32 | 33 | import java.net.InetSocketAddress; |
@@ -95,13 +96,20 @@ public void testConnectToBlackholeTimesOut() { |
95 | 96 | long start = System.nanoTime(); |
96 | 97 | int rc = NF.connectAddrInfoTimeout(fd, addrInfo, 500); |
97 | 98 | 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); |
103 | 112 | 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); |
105 | 113 | } finally { |
106 | 114 | NF.freeAddrInfo(addrInfo); |
107 | 115 | NF.close(fd); |
|
0 commit comments