Skip to content

Commit fdc2686

Browse files
committed
[FLINK-39105][rest] Fix RestClientTest.testConnectionTimeout to handle environment-dependent exception types
The test connects to 192.0.2.1 (RFC 5737 TEST-NET-1) with a 1ms connection timeout and asserts ConnectTimeoutException. On CI runners without a route to this address, the OS immediately returns "Network is unreachable" (AnnotatedSocketException) instead of timing out, causing the test to fail. Both ConnectTimeoutException and AnnotatedSocketException are SocketException subtypes, so the assertion now uses SocketException as the expected cause type. The existing hasMessageContaining(unroutableIp) check still verifies the failure is for the correct destination. Note: on environments where the OS rejects immediately, the configured connection timeout is never exercised. The test still verifies that connection failures propagate correctly, but does not validate the timeout code path on those environments. A more robust approach would require simulating a non-completing TCP handshake, which is not portable.
1 parent 45c62ca commit fdc2686

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
3939
import org.apache.flink.shaded.netty4.io.netty.channel.Channel;
40-
import org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException;
4140
import org.apache.flink.shaded.netty4.io.netty.channel.DefaultSelectStrategyFactory;
4241
import org.apache.flink.shaded.netty4.io.netty.channel.MultiThreadIoEventLoopGroup;
4342
import org.apache.flink.shaded.netty4.io.netty.channel.SelectStrategy;
@@ -54,6 +53,7 @@
5453
import java.lang.reflect.Field;
5554
import java.net.ServerSocket;
5655
import java.net.Socket;
56+
import java.net.SocketException;
5757
import java.time.Duration;
5858
import java.util.Arrays;
5959
import java.util.Collections;
@@ -111,9 +111,13 @@ void testConnectionTimeout() throws Exception {
111111
EmptyMessageParameters.getInstance(),
112112
EmptyRequestBody.getInstance());
113113

114+
// Depending on the environment, connecting to a non-routable address may fail with
115+
// either a ConnectTimeoutException (timeout fires before the OS responds) or a
116+
// SocketException such as "Network is unreachable" (OS rejects immediately).
117+
// Both are SocketException subtypes.
114118
FlinkAssertions.assertThatFuture(future)
115119
.eventuallyFailsWith(ExecutionException.class)
116-
.withCauseInstanceOf(ConnectTimeoutException.class)
120+
.withCauseInstanceOf(SocketException.class)
117121
.extracting(Throwable::getCause, as(InstanceOfAssertFactories.THROWABLE))
118122
.hasMessageContaining(unroutableIp);
119123
}

0 commit comments

Comments
 (0)