You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2011/12/30 11:25:23 UTC

svn commit: r1225784 - in /maven/surefire/trunk: surefire-integration-tests/src/test/resources/surefire-813-wrong-testCount/ surefire-integration-tests/src/test/resources/surefire-813-wrong-testCount/src/test/java/ surefire-providers/surefire-junit47/ ...

Author: krosenvold
Date: Fri Dec 30 10:25:23 2011
New Revision: 1225784

URL: http://svn.apache.org/viewvc?rev=1225784&view=rev
Log:
[SUREFIRE-813] Randomly wrong testcount

Test-case submitted by nkeyval, fixed with unit test

Added:
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java   (with props)
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java   (with props)
Removed:
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-813-wrong-testCount/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-813-wrong-testCount/src/test/java/Test6.java
Modified:
    maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml?rev=1225784&r1=1225783&r2=1225784&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/pom.xml Fri Dec 30 10:25:23 2011
@@ -75,7 +75,7 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <jvm>${java.home}/bin/java</jvm>
-          <redirectTestOutputToFile>false</redirectTestOutputToFile>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
         </configuration>
         <dependencies>
           <dependency>

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java?rev=1225784&r1=1225783&r2=1225784&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java Fri Dec 30 10:25:23 2011
@@ -76,7 +76,7 @@ public class LogicalStream
         }
     }
 
-    public void writeDetails( ConsoleOutputReceiver outputReceiver )
+    public synchronized void writeDetails( ConsoleOutputReceiver outputReceiver )
     {
         for ( Entry entry : output )
         {

Added: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java?rev=1225784&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java (added)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java Fri Dec 30 10:25:23 2011
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.surefire.junitcore;
+
+import java.util.HashMap;
+import java.util.concurrent.ExecutionException;
+import org.apache.maven.plugin.surefire.report.FileReporterFactory;
+import org.apache.maven.surefire.report.ConsoleOutputCapture;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.apache.maven.surefire.report.DefaultConsoleReporter;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+import org.junit.runner.Computer;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class JUnitCoreTester
+{
+
+    private final Computer computer;
+
+    public JUnitCoreTester()
+    {
+        this(new Computer());
+    }
+
+    public JUnitCoreTester( Computer computer )
+    {
+        this.computer = computer;
+    }
+
+    public Result run( boolean parallelClasses, Class<?>... classes )
+        throws TestSetFailedException, ExecutionException
+    {
+        ReporterFactory reporterManagerFactory = FileReporterFactory.defaultNoXml();
+
+        final HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
+        RunListener reporter =
+            ConcurrentReporterManager.createInstance( classMethodCounts, reporterManagerFactory, parallelClasses, false,
+                                                      new DefaultConsoleReporter( System.out ) );
+        ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) reporter );
+
+        JUnitCoreRunListener runListener = new JUnitCoreRunListener( reporter, classMethodCounts );
+        JUnitCore junitCore = new JUnitCore();
+
+        junitCore.addListener( runListener );
+        final Result run = junitCore.run( computer, classes );
+        junitCore.removeListener( runListener );
+        reporterManagerFactory.close();
+        if (computer instanceof  ConfigurableParallelComputer){
+            ((ConfigurableParallelComputer)computer).close();
+        }
+        return run;
+    }
+
+
+}

Propchange: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java?rev=1225784&r1=1225783&r2=1225784&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTest.java Fri Dec 30 10:25:23 2011
@@ -16,20 +16,10 @@
  */
 package org.apache.maven.surefire.junitcore;
 
-import java.io.File;
-import java.util.HashMap;
-import org.apache.maven.plugin.surefire.report.FileReporterFactory;
-import org.apache.maven.surefire.report.DefaultConsoleReporter;
-import org.apache.maven.surefire.report.ReporterConfiguration;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-
 import junit.framework.Assert;
 import junit.framework.TestCase;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.Computer;
-import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
 
@@ -119,24 +109,7 @@ public class MavenSurefireJUnit47RunnerT
     public void testSurefireShouldBeAbleToReportRunStatusEvenWithFailingTests()
         throws Exception
     {
-        ReporterFactory reporterManagerFactory = FileReporterFactory.defaultNoXml( );
-
-        final HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
-        RunListener reporter =
-            ConcurrentReporterManager.createInstance( classMethodCounts, reporterManagerFactory, false, false,
-                                                      new DefaultConsoleReporter( System.out ) );
-
-        org.junit.runner.notification.RunListener concurrentReportingRunListener =
-            new JUnitCoreRunListener( reporter, classMethodCounts );
-        Computer computer = new Computer();
-
-        JUnitCore junitCore = new JUnitCore();
-
-        junitCore.addListener( concurrentReportingRunListener );
-
-        Result result = junitCore.run( computer, FailingTestClassTestNot.class );
-
-        junitCore.removeListener( concurrentReportingRunListener );
+        Result result = new JUnitCoreTester().run( false, FailingTestClassTestNot.class );
 
         Assert.assertEquals( "JUnit should report correctly number of test ran(Finished)", 0, result.getRunCount() );
 
@@ -152,12 +125,6 @@ public class MavenSurefireJUnit47RunnerT
         Assert.assertEquals( "The exception thrown by the failing TestCase", RuntimeException.class,
                              result.getFailures().get( 0 ).getException().getClass() );
 
-        reporterManagerFactory.close();
-    }
-
-    private ReporterConfiguration getReporterConfiguration()
-    {
-        return new ReporterConfiguration( new File( "." ), true );
     }
 
     /**

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java?rev=1225784&r1=1225783&r2=1225784&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit48RunnerTest.java Fri Dec 30 10:25:23 2011
@@ -16,20 +16,10 @@
  */
 package org.apache.maven.surefire.junitcore;
 
-import java.io.File;
-import java.util.HashMap;
-import org.apache.maven.plugin.surefire.report.FileReporterFactory;
-import org.apache.maven.surefire.report.DefaultConsoleReporter;
-import org.apache.maven.surefire.report.ReporterConfiguration;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-
 import junit.framework.Assert;
 import junit.framework.TestCase;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.Computer;
-import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
 
@@ -119,24 +109,7 @@ public class MavenSurefireJUnit48RunnerT
     public void testSurefireShouldBeAbleToReportRunStatusEvenWithFailingTests()
         throws Exception
     {
-        ReporterFactory reporterManagerFactory = FileReporterFactory.defaultNoXml( );
-
-        final HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
-        RunListener reporter =
-            ConcurrentReporterManager.createInstance( classMethodCounts, reporterManagerFactory, false, false,
-                                                      new DefaultConsoleReporter( System.out ) );
-
-        org.junit.runner.notification.RunListener concurrentReportingRunListener =
-            new JUnitCoreRunListener( reporter, classMethodCounts );
-        Computer computer = new Computer();
-
-        JUnitCore junitCore = new JUnitCore();
-
-        junitCore.addListener( concurrentReportingRunListener );
-
-        Result result = junitCore.run( computer, FailingTestClassTestNot.class );
-
-        junitCore.removeListener( concurrentReportingRunListener );
+        Result result = new JUnitCoreTester().run( false, FailingTestClassTestNot.class );
 
         Assert.assertEquals( "JUnit should report correctly number of test ran(Finished)", 0, result.getRunCount() );
 
@@ -152,12 +125,6 @@ public class MavenSurefireJUnit48RunnerT
         Assert.assertEquals( "The exception thrown by the failing TestCase", RuntimeException.class,
                              result.getFailures().get( 0 ).getException().getClass() );
 
-        reporterManagerFactory.close();
-    }
-
-    private ReporterConfiguration getReporterConfiguration()
-    {
-        return new ReporterConfiguration( new File( "." ), true );
     }
 
     /**

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java?rev=1225784&r1=1225783&r2=1225784&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire746Test.java Fri Dec 30 10:25:23 2011
@@ -92,7 +92,7 @@ public class Surefire746Test {
 
         RunListener listener = ConcurrentReporterManager.createInstance(testSetMap, reporterFactory, false, false, consoleLogger);
 
-        TestsToRun testsToRun = new TestsToRun(Arrays.asList(new Class[]{TestClassTest.class}));
+        TestsToRun testsToRun = new TestsToRun(Arrays.asList( TestClassTest.class ));
 
         org.junit.runner.notification.RunListener jUnit4RunListener = new JUnitCoreRunListener(listener, testSetMap);
 

Added: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java?rev=1225784&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java (added)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java Fri Dec 30 10:25:23 2011
@@ -0,0 +1,62 @@
+package org.apache.maven.surefire.junitcore;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.Result;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * @author Kristian Rosenvold
+ * @author nkeyval
+ */
+public class Surefire813IncorrectResultTest
+{
+
+
+    @Test
+    public void dcount()
+        throws TestSetFailedException, ExecutionException
+    {
+        JUnitCoreTester jUnitCoreTester = new JUnitCoreTester();
+        final Result run = jUnitCoreTester.run( true, Test6.class );
+        assertEquals(0, run.getFailureCount());
+    }
+
+    public static class Test6 {
+      private final CountDownLatch latch = new CountDownLatch( 1 );
+
+      @Test
+      public void test61() throws Exception {
+          System.out.println("Hey");
+      }
+
+      @After
+      public void tearDown() throws Exception {
+          new MyThread().start();
+          latch.await();
+      }
+
+      private static final String s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+
+      public void synchPrint(){
+        for (int i=0; i<1000; ++i){ // Increase this number if it does no fail
+          System.out.println(i+":"+s);
+        }
+      }
+
+        private class MyThread extends Thread {
+        @Override
+        public void run() {
+          System.out.println(s);
+          latch.countDown();
+          synchPrint();
+        }
+      }
+    }
+
+}

Propchange: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Surefire813IncorrectResultTest.java
------------------------------------------------------------------------------
    svn:eol-style = native