@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());
		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);
		// we should have found a heuristic address
		assertNotNull(add);
		// make sure that we returned the InetAddress.getLocalHost as a heuristic
		assertEquals(InetAddress.getLocalHost(), add);
	}
}