Repository: maven-surefire Updated Branches: refs/heads/master 1c2698a75 -> 3cecbd360
[SUREFIRE-797] Parallel junit does not run in parallel when a Suite is used at the top level Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/3cecbd36 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/3cecbd36 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/3cecbd36 Branch: refs/heads/master Commit: 3cecbd360e74aff19b838e4c8d86bc99c4ad2bee Parents: 1c2698a Author: tibordigana <tibo...@lycos.com> Authored: Wed Oct 8 20:36:33 2014 +0200 Committer: tibordigana <tibo...@lycos.com> Committed: Wed Oct 8 20:36:33 2014 +0200 ---------------------------------------------------------------------- ...refire747MethodParallelWithSuiteCountIT.java | 67 +++++++++++++++++++- .../src/test/java/surefire747/SuiteTest1.java | 23 ++++++- .../src/test/java/surefire747/SuiteTest2.java | 23 ++++++- .../src/test/java/surefire747/TestSuite.java | 16 +++++ 4 files changed, 120 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3cecbd36/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire747MethodParallelWithSuiteCountIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire747MethodParallelWithSuiteCountIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire747MethodParallelWithSuiteCountIT.java index 35fc601..bedf3a8 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire747MethodParallelWithSuiteCountIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire747MethodParallelWithSuiteCountIT.java @@ -19,10 +19,20 @@ package org.apache.maven.surefire.its.jiras; * under the License. */ +import org.apache.maven.it.VerificationException; +import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + /** * @author Kristian Rosenvold */ @@ -30,21 +40,72 @@ public class Surefire747MethodParallelWithSuiteCountIT extends SurefireJUnit4IntegrationTestCase { + private static Set<String> printTestLines( OutputValidator validator, String pattern ) + throws VerificationException + { + Set<String> log = new TreeSet<String>( validator.loadLogLines() ); + for ( Iterator<String> it = log.iterator(); it.hasNext(); ) + { + String line = it.next(); + if ( !line.contains( pattern ) ) + { + it.remove(); + } + } + return log; + } + + private static long duration( String logLine ) + { + return Integer.decode( logLine.split( "=" )[1] ); + } + @Test public void testMethodsParallelWithSuite() + throws VerificationException { - unpack().executeTest().verifyErrorFree( 6 ); + OutputValidator validator = unpack().executeTest().verifyErrorFree( 6 ); + Set<String> testLines = printTestLines( validator, "test finished after duration=" ); + assertThat( testLines.size(), is( 2 ) ); + for ( String testLine : testLines ) + { + long duration = duration( testLine ); + long min = 250, max = 750; + assertTrue( String.format( "duration %d should be between %d and %d millis", duration, min, max ), + duration > min && duration < max ); + } + Set<String> suiteLines = printTestLines( validator, "suite finished after duration=" ); + assertThat( suiteLines.size(), is( 1 ) ); + long duration = duration( suiteLines.iterator().next() ); + long min = 750, max = 1250; + assertTrue( String.format( "duration %d should be between %d and %d millis", duration, min, max ), + duration > min && duration < max ); } @Test public void testClassesParallelWithSuite() + throws VerificationException { - unpack().parallelClasses().executeTest().verifyErrorFree( 6 ); + OutputValidator validator = unpack().parallelClasses().executeTest().verifyErrorFree( 6 ); + Set<String> testLines = printTestLines( validator, "test finished after duration=" ); + assertThat( testLines.size(), is( 2 ) ); + for ( String testLine : testLines ) + { + long duration = duration( testLine ); + long min = 1250, max = 1750; + assertTrue( String.format( "duration %d should be between %d and %d millis", duration, min, max ), + duration > min && duration < max ); + } + Set<String> suiteLines = printTestLines( validator, "suite finished after duration=" ); + assertThat( suiteLines.size(), is( 1 ) ); + long duration = duration( suiteLines.iterator().next() ); + long min = 1250, max = 1750; + assertTrue( String.format( "duration %d should be between %d and %d millis", duration, min, max ), + duration > min && duration < max ); } public SurefireLauncher unpack() { return unpack( "junit47-parallel-with-suite" ); } - } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3cecbd36/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest1.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest1.java b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest1.java index 7df8a1f..96138c8 100644 --- a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest1.java +++ b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest1.java @@ -20,7 +20,9 @@ package surefire747; */ import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -28,11 +30,26 @@ import org.junit.Test; */ public class SuiteTest1 { + private static long startedAt; + public SuiteTest1() { System.out.println( "SuiteTest1.constructor" ); } + @BeforeClass + public static void beforeClass() + { + startedAt = System.currentTimeMillis(); + } + + @AfterClass + public static void afterClass() + { + System.out.println( String.format( "%s test finished after duration=%d", SuiteTest1.class.getSimpleName(), + System.currentTimeMillis() - startedAt ) ); + } + @Before public void setUp() { @@ -50,7 +67,7 @@ public class SuiteTest1 throws InterruptedException { System.out.println( "begin SuiteTest1.first" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest1.first" ); } @@ -59,7 +76,7 @@ public class SuiteTest1 throws InterruptedException { System.out.println( "begin SuiteTest1.second" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest1.second" ); } @@ -68,7 +85,7 @@ public class SuiteTest1 throws InterruptedException { System.out.println( "begin SuiteTest1.third" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest1.third" ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3cecbd36/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest2.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest2.java b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest2.java index 32247dd..b5eb77c 100644 --- a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest2.java +++ b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/SuiteTest2.java @@ -20,7 +20,9 @@ package surefire747; */ import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -28,11 +30,26 @@ import org.junit.Test; */ public class SuiteTest2 { + private static long startedAt; + public SuiteTest2() { System.out.println( "SuiteTest2.constructor" ); } + @BeforeClass + public static void beforeClass() + { + startedAt = System.currentTimeMillis(); + } + + @AfterClass + public static void afterClass() + { + System.out.println( String.format( "%s test finished after duration=%d", SuiteTest2.class.getSimpleName(), + System.currentTimeMillis() - startedAt ) ); + } + @Before public void setUp() { @@ -50,7 +67,7 @@ public class SuiteTest2 throws InterruptedException { System.out.println( "begin SuiteTest2.first" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest2.first" ); } @@ -59,7 +76,7 @@ public class SuiteTest2 throws InterruptedException { System.out.println( "begin SuiteTest2.second" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest2.second" ); } @@ -68,7 +85,7 @@ public class SuiteTest2 throws InterruptedException { System.out.println( "begin SuiteTest2.third" ); - Thread.sleep( 300 ); + Thread.sleep( 500 ); System.out.println( "end SuiteTest2.third" ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3cecbd36/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/TestSuite.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/TestSuite.java b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/TestSuite.java index 56ac35e..4e95481 100644 --- a/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/TestSuite.java +++ b/surefire-integration-tests/src/test/resources/junit47-parallel-with-suite/src/test/java/surefire747/TestSuite.java @@ -19,6 +19,8 @@ package surefire747; * under the License. */ +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -33,4 +35,18 @@ import org.junit.runners.Suite; }) public class TestSuite { + private static long startedAt; + + @BeforeClass + public static void beforeClass() + { + startedAt = System.currentTimeMillis(); + } + + @AfterClass + public static void afterClass() + { + System.out.println( String.format( "%s suite finished after duration=%d", TestSuite.class.getSimpleName(), + System.currentTimeMillis() - startedAt ) ); + } }