From da1b319d83cfb77281bcdebe648d4ee95f5b1706 Mon Sep 17 00:00:00 2001 From: "xuewei.linxuewei" Date: Tue, 16 Oct 2018 13:58:07 +0800 Subject: [PATCH] [FLINK-4052] using non-local unreachable ip:port to fix unstable Test testReturnLocalHostAddressUsingHeuristics Change-Id: If6dfbbde2190dead5e918dbdaf15b551975acd17 --- .../runtime/net/ConnectionUtilsTest.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java index 3f9ee8e6a8d33..c945ce234ef9a 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/net/ConnectionUtilsTest.java @@ -43,24 +43,22 @@ public class ConnectionUtilsTest { @Test public void testReturnLocalHostAddressUsingHeuristics() throws Exception { - try (ServerSocket blocker = new ServerSocket(0, 1, InetAddress.getLocalHost())) { - // the "blocker" server socket simply does not accept connections - // this address is consequently "unreachable" - InetSocketAddress unreachable = new InetSocketAddress("localhost", blocker.getLocalPort()); + // instead of using a unstable localhost:port as "unreachable" to cause Test fails unstably + // using a Absolutely unreachable outside ip:port + InetSocketAddress unreachable = new InetSocketAddress("8.8.8.8", 0xFFFF); - final long start = System.nanoTime(); - InetAddress add = ConnectionUtils.findConnectingAddress(unreachable, 2000, 400); + final long start = System.nanoTime(); + InetAddress add = ConnectionUtils.findConnectingAddress(unreachable, 2000, 400); - // check that it did not take forever (max 30 seconds) - // this check can unfortunately not be too tight, or it will be flaky on some CI infrastructure - assertTrue(System.nanoTime() - start < 30_000_000_000L); + // check that it did not take forever (max 30 seconds) + // this check can unfortunately not be too tight, or it will be flaky on some CI infrastructure + assertTrue(System.nanoTime() - start < 30_000_000_000L); - // we should have found a heuristic address - assertNotNull(add); + // we should have found a heuristic address + assertNotNull(add); - // make sure that we returned the InetAddress.getLocalHost as a heuristic - assertEquals(InetAddress.getLocalHost(), add); - } + // make sure that we returned the InetAddress.getLocalHost as a heuristic + assertEquals(InetAddress.getLocalHost(), add); } @Test