Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-4052] using non-local unreachable ip:port to fix unstable Test testReturnLocalHostAddressUsingHeuristics #6853

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down