]> source.dussan.org Git - sonarqube.git/commitdiff
Fix test false-positives when port is already in use
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 4 Sep 2015 07:13:12 +0000 (09:13 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 4 Sep 2015 07:13:12 +0000 (09:13 +0200)
server/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java

index 44fcfb7677d1f65620d0fdca562f84eaac707ad9..5dd5813917fd03b4c3ee94df7f810d2a466399b9 100644 (file)
@@ -39,7 +39,7 @@ public class NetworkUtils {
     try  {
       socket = new ServerSocket();
       socket.setReuseAddress(true);
-      socket.bind(new InetSocketAddress(0));
+      socket.bind(new InetSocketAddress("localhost", 0));
       return socket.getLocalPort();
 
     } catch (IOException e) {
index f19f42c5345711c8acebd1c295542bdbda47ab08..576d274a6694f719612f6110a2c9256610e0d64d 100644 (file)
@@ -111,9 +111,9 @@ public class DefaultHttpDownloaderTest {
         }
       }
     });
-    SocketAddress address = socketConnection.connect(new InetSocketAddress(0));
+    SocketAddress address = socketConnection.connect(new InetSocketAddress("localhost", 0));
 
-    baseUrl = "http://0.0.0.0:" + ((InetSocketAddress) address).getPort();
+    baseUrl = String.format("http://%s:%d", ((InetSocketAddress) address).getAddress().getHostAddress(), ((InetSocketAddress) address).getPort());
   }
 
   @AfterClass
@@ -197,7 +197,7 @@ public class DefaultHttpDownloaderTest {
     File toFile = new File(toDir, "downloadToFile.txt");
 
     try {
-      int port = new InetSocketAddress(0).getPort();
+      int port = new InetSocketAddress("localhost", 0).getPort();
       new DefaultHttpDownloader(new Settings()).download(new URI("http://localhost:" + port), toFile);
     } catch (SonarException e) {
       assertThat(toFile).doesNotExist();