From fa9fa29f8f5704dbfe8f84f7621cebdb55152725 Mon Sep 17 00:00:00 2001 From: MishaDemianenko Date: Wed, 31 Oct 2018 16:06:19 +0100 Subject: [PATCH] Backport NeoServerPortConflictIT flaky test fixes to 3.4 --- .../neo4j/server/NeoServerPortConflictIT.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/community/server/src/test/java/org/neo4j/server/NeoServerPortConflictIT.java b/community/server/src/test/java/org/neo4j/server/NeoServerPortConflictIT.java index 82e34eac19c01..2da048648d668 100644 --- a/community/server/src/test/java/org/neo4j/server/NeoServerPortConflictIT.java +++ b/community/server/src/test/java/org/neo4j/server/NeoServerPortConflictIT.java @@ -27,7 +27,6 @@ import org.neo4j.helpers.ListenSocketAddress; import org.neo4j.logging.AssertableLogProvider; -import org.neo4j.ports.allocation.PortAuthority; import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.test.server.ExclusiveServerTestBase; @@ -38,14 +37,13 @@ public class NeoServerPortConflictIT extends ExclusiveServerTestBase { + @Test public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException { - int serverPort = PortAuthority.allocatePort(); - ListenSocketAddress contestedAddress = new ListenSocketAddress( "localhost", serverPort ); - try ( ServerSocket ignored = new ServerSocket( - contestedAddress.getPort(), 0, InetAddress.getByName( contestedAddress.getHostname() ) ) ) + try ( ServerSocket socket = new ServerSocket( 0, 0, InetAddress.getLocalHost() ) ) { + ListenSocketAddress contestedAddress = new ListenSocketAddress( socket.getInetAddress().getHostName(), socket.getLocalPort() ); AssertableLogProvider logProvider = new AssertableLogProvider(); CommunityNeoServer server = CommunityServerBuilder.server( logProvider ) .onAddress( contestedAddress ) @@ -76,17 +74,14 @@ public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException @Test public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException { - int serverPort = PortAuthority.allocatePort(); - int httpsPort = PortAuthority.allocatePort(); - ListenSocketAddress unContestedAddress = new ListenSocketAddress( "localhost", serverPort ); - ListenSocketAddress contestedAddress = new ListenSocketAddress( "localhost", httpsPort ); - try ( ServerSocket ignored = new ServerSocket( - contestedAddress.getPort(), 0, InetAddress.getByName( contestedAddress.getHostname() ) ) ) + try ( ServerSocket httpsSocket = new ServerSocket( 0, 0, InetAddress.getLocalHost() ) ) { + ListenSocketAddress unContestedAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), 0 ); + ListenSocketAddress httpsAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), httpsSocket.getLocalPort() ); AssertableLogProvider logProvider = new AssertableLogProvider(); CommunityNeoServer server = CommunityServerBuilder.server( logProvider ) .onAddress( unContestedAddress ) - .onHttpsAddress( contestedAddress ) + .onHttpsAddress( httpsAddress ) .withHttpsEnabled() .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); @@ -106,7 +101,7 @@ public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException "Failed to start Neo4j on %s: %s", unContestedAddress, format( "At least one of the addresses %s or %s is already in use, cannot bind to it.", - unContestedAddress, contestedAddress ) + unContestedAddress, httpsAddress ) ) ); server.stop();