You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/08/20 20:57:29 UTC

[maven-wagon] branch stabilize created (now edffe69)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch stabilize
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git.


      at edffe69  Randomize port of ServerSocket

This branch includes the following new commits:

     new edffe69  Randomize port of ServerSocket

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-wagon] 01/01: Randomize port of ServerSocket

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch stabilize
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit edffe69a86130453272dedef3e68128c9825a9d4
Author: rfscholte <rf...@apache.org>
AuthorDate: Tue Aug 20 22:57:21 2019 +0200

    Randomize port of ServerSocket
---
 .../src/main/java/org/apache/maven/wagon/WagonTestCase.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
index cdcdc67..28ec811 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
@@ -49,6 +49,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Random;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -138,11 +139,19 @@ public abstract class WagonTestCase
 
     public static ServerSocket newServerSocket( int... ports )
     {
-        for ( int port : ports )
+        // there can be a timing issue while handing over the port to the actual server, so start at random index
+        final int offset = new Random( ports.length ).nextInt();
+
+        for ( int index = 0 ; index < ports.length; index++ )
         {
             try
             {
-                return new ServerSocket( port );
+                ServerSocket serverSocket = new ServerSocket( ports[( offset + index ) % ports.length] );
+                
+                if ( serverSocket.getLocalPort() != -1 )
+                {
+                    return serverSocket;
+                }
             }
             catch ( IOException ex )
             {