This is an automated email from the ASF dual-hosted git repository.

MartijnVisser pushed a commit to branch release-1.20
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.20 by this push:
     new 02b16664af7 [FLINK-39105][rest] Fix 
RestClientTest.testConnectionTimeout to handle environment-dependent exception 
types
02b16664af7 is described below

commit 02b16664af70c3cfdec017f859719d3209cfa592
Author: Martijn Visser <[email protected]>
AuthorDate: Wed Feb 18 11:06:00 2026 +0100

    [FLINK-39105][rest] Fix RestClientTest.testConnectionTimeout to handle 
environment-dependent exception types
    
    The test connects to 240.0.0.0 (reserved space, RFC 1112) 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.
    
    (cherry picked from commit fdc2686e33d8dd1a338e3cc1432a6b8b2cad6d71)
---
 .../test/java/org/apache/flink/runtime/rest/RestClientTest.java   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java 
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java
index cd6b76ec6a2..ac91c0ca77b 100644
--- 
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java
+++ 
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java
@@ -36,7 +36,6 @@ import org.apache.flink.util.function.CheckedSupplier;
 
 import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
 import org.apache.flink.shaded.netty4.io.netty.channel.Channel;
-import org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException;
 import 
org.apache.flink.shaded.netty4.io.netty.channel.DefaultSelectStrategyFactory;
 import org.apache.flink.shaded.netty4.io.netty.channel.SelectStrategy;
 import org.apache.flink.shaded.netty4.io.netty.channel.SelectStrategyFactory;
@@ -51,6 +50,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.SocketException;
 import java.time.Duration;
 import java.util.Arrays;
 import java.util.Collections;
@@ -107,9 +107,13 @@ class RestClientTest {
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
 
+            // Depending on the environment, connecting to a non-routable 
address may fail with
+            // either a ConnectTimeoutException (timeout fires before the OS 
responds) or a
+            // SocketException such as "Network is unreachable" (OS rejects 
immediately).
+            // Both are SocketException subtypes.
             FlinkAssertions.assertThatFuture(future)
                     .eventuallyFailsWith(ExecutionException.class)
-                    .withCauseInstanceOf(ConnectTimeoutException.class)
+                    .withCauseInstanceOf(SocketException.class)
                     .extracting(Throwable::getCause, 
as(InstanceOfAssertFactories.THROWABLE))
                     .hasMessageContaining(unroutableIp);
         }

Reply via email to