maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tibordig...@apache.org
Subject [1/2] maven-surefire git commit: awaiting MasterProcessReader up in providers
Date Tue, 08 Sep 2015 02:45:15 GMT
Repository: maven-surefire
Updated Branches:
  refs/heads/master 78a885f8b -> e87f8807d


awaiting MasterProcessReader up in providers


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/d8770d69
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/d8770d69
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/d8770d69

Branch: refs/heads/master
Commit: d8770d69f62eb66ccd86db9341b0c96c32d54f0a
Parents: 78a885f
Author: Tibor17 <tibor17@lycos.com>
Authored: Tue Sep 8 04:43:56 2015 +0200
Committer: Tibor17 <tibor17@lycos.com>
Committed: Tue Sep 8 04:43:56 2015 +0200

----------------------------------------------------------------------
 .../surefire/booter/MasterProcessReader.java    | 27 ++++++++++++++++++++
 .../booter/MasterProcessReaderTest.java         | 10 ++++++++
 .../maven/surefire/junit4/JUnit4Provider.java   |  5 ++++
 .../surefire/junitcore/JUnitCoreProvider.java   |  7 ++++-
 .../maven/surefire/testng/TestNGProvider.java   |  5 ++++
 5 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d8770d69/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java
b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java
index 8c36bd2..ab45d81 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/MasterProcessReader.java
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
 import java.io.DataInputStream;
 import java.io.EOFException;
 import java.io.IOException;
@@ -27,6 +29,7 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 
 import static java.lang.Thread.State.NEW;
@@ -64,6 +67,8 @@ public final class MasterProcessReader
 
     private final Node head = new Node();
 
+    private final CountDownLatch startMonitor = new CountDownLatch( 1 );
+
     private volatile Node tail = head;
 
     private static class Node
@@ -82,6 +87,27 @@ public final class MasterProcessReader
         return reader;
     }
 
+    public boolean awaitStarted()
+        throws TestSetFailedException
+    {
+        if ( state.get() == RUNNABLE )
+        {
+            try
+            {
+                startMonitor.await();
+                return true;
+            }
+            catch ( InterruptedException e )
+            {
+                throw new TestSetFailedException( e.getLocalizedMessage() );
+            }
+        }
+        else
+        {
+            return false;
+        }
+    }
+
     /**
      * @param listener listener called with <em>Any</em> {@link MasterProcessCommand
command type}
      */
@@ -367,6 +393,7 @@ public final class MasterProcessReader
     {
         public void run()
         {
+            MasterProcessReader.this.startMonitor.countDown();
             DataInputStream stdIn = new DataInputStream( System.in );
             boolean isTestSetFinished = false;
             try

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d8770d69/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessReaderTest.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessReaderTest.java
b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessReaderTest.java
index ae299c1..4e1f0d0 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessReaderTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/MasterProcessReaderTest.java
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
+import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -200,6 +201,15 @@ public class MasterProcessReaderTest
         }
     }
 
+    @Test( timeout = 15000 )
+    public void shouldAwaitReaderUp()
+        throws TestSetFailedException
+    {
+        assertTrue( reader.awaitStarted() );
+        reader.stop();
+        assertFalse( reader.awaitStarted() );
+    }
+
     private class SystemInputStream
         extends InputStream
     {

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d8770d69/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
index 2276eac..3321a82 100644
--- a/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
+++ b/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
@@ -166,6 +166,11 @@ public class JUnit4Provider
                                                 ? createTestsDescription()
                                                 : createDescription( UNDETERMINED_TESTS_DESCRIPTION
) );
 
+            if ( commandsReader != null )
+            {
+                commandsReader.awaitStarted();
+            }
+
             for ( Class aTestsToRun : testsToRun )
             {
                 executeTestSet( aTestsToRun, reporter, notifier );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d8770d69/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
index 29687ef..2c7d5c9 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
@@ -161,6 +161,11 @@ public class JUnitCoreProvider
         {
             JUnitCoreWrapper core = new JUnitCoreWrapper( notifier, jUnitCoreParameters,
consoleLogger, isFailFast() );
 
+            if ( commandsReader != null )
+            {
+                commandsReader.awaitStarted();
+            }
+
             core.execute( testsToRun, customRunListeners, filter );
 
             // Rerun failing tests if rerunFailingTestsCount is larger than 0
@@ -176,13 +181,13 @@ public class JUnitCoreProvider
                     core.execute( testsToRun, failingMethodsFilter );
                 }
             }
+            return reporterFactory.close();
         }
         finally
         {
             notifier.removeListeners();
             closeCommandsReader();
         }
-        return reporterFactory.close();
     }
 
     private boolean isRerunFailingTests()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/d8770d69/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
index 77b5c75..a317042 100644
--- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
+++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
@@ -94,6 +94,11 @@ public class TestNGProvider
                 registerPleaseStopListener();
             }
 
+            if ( commandsReader != null )
+            {
+                commandsReader.awaitStarted();
+            }
+
             final ReporterFactory reporterFactory = providerParameters.getReporterFactory();
 
             if ( isTestNGXmlTestSuite( testRequest ) )


Mime
View raw message