You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2018/09/10 00:37:04 UTC
[maven-surefire] 01/06: [SUREFIRE-1561] Logs in Parallel Tests are
mixed up when forkMode=never or forkCount=0
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch BUILDFIX
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 64cf3e1d2fe230693e068964a5dfab8b04bb9684
Author: Tibor17 <ti...@apache.org>
AuthorDate: Sun Sep 9 21:06:39 2018 +0200
[SUREFIRE-1561] Logs in Parallel Tests are mixed up when forkMode=never or forkCount=0
---
.../plugin/surefire/report/TestSetRunListener.java | 2 +-
.../surefire/its/fixture/OutputValidator.java | 2 +-
.../jiras/Surefire1177TestngParallelSuitesIT.java | 38 ++++++++++++++++++----
.../test/java/testng/suiteXml/TestNGSuiteTest.java | 9 +++--
4 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
index 329ba79..1ed32f9 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
@@ -148,7 +148,7 @@ public class TestSetRunListener
}
@Override
- public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ public synchronized void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
{
try
{
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java
index 1c53e55..882ed9c 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/OutputValidator.java
@@ -105,7 +105,7 @@ public class OutputValidator
return this;
}
- public Collection<String> loadLogLines()
+ public List<String> loadLogLines()
throws VerificationException
{
return verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java
index 8c2c213..28cc78c 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java
@@ -20,6 +20,7 @@ package org.apache.maven.surefire.its.jiras;
*/
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;
@@ -38,18 +39,41 @@ import static org.hamcrest.Matchers.startsWith;
public class Surefire1177TestngParallelSuitesIT
extends SurefireJUnit4IntegrationTestCase
{
+ private static final String EXPECTED_LINE = "TestNGSuiteTest#shouldRunAndPrintItself()";
+ private static final String UNEXPECTED_LINE = "ShouldNotRunTest#shouldNotRun()";
+
@Test
- public void shouldRunTwoSuitesInParallel()
+ public void twoSuitesInParallel()
throws VerificationException
{
assumeJavaVersion( 1.7d );
- unpack().executeTest()
- .verifyErrorFree( 2 )
- .assertThatLogLine( containsString( "ShouldNotRunTest#shouldNotRun()" ), is( 0 ) )
- .assertThatLogLine( startsWith( "TestNGSuiteTest#shouldRunAndPrintItself()" ), is( 2 ) )
- .assertThatLogLine( is( "TestNGSuiteTest#shouldRunAndPrintItself() 1." ), is( 1 ) )
- .assertThatLogLine( is( "TestNGSuiteTest#shouldRunAndPrintItself() 2." ), is( 1 ) );
+ OutputValidator validator = unpack()
+ .forkMode( "never" )
+ .executeTest()
+ .verifyErrorFree( 2 );
+
+ validator.assertThatLogLine( startsWith( EXPECTED_LINE ), is( 2 ) );
+ validator.assertThatLogLine( is( EXPECTED_LINE + " 1." ), is( 1 ) );
+ validator.assertThatLogLine( is( EXPECTED_LINE + " 2." ), is( 1 ) );
+ validator.assertThatLogLine( containsString( UNEXPECTED_LINE ), is( 0 ) );
+ }
+
+ @Test
+ public void twoSuitesInParallelForked()
+ throws VerificationException
+ {
+ assumeJavaVersion( 1.7d );
+
+ OutputValidator validator = unpack()
+ .forkMode( "once" )
+ .executeTest()
+ .verifyErrorFree( 2 );
+
+ validator.assertThatLogLine( startsWith( EXPECTED_LINE ), is( 2 ) );
+ validator.assertThatLogLine( is( EXPECTED_LINE + " 1." ), is( 1 ) );
+ validator.assertThatLogLine( is( EXPECTED_LINE + " 2." ), is( 1 ) );
+ validator.assertThatLogLine( containsString( UNEXPECTED_LINE ), is( 0 ) );
}
private SurefireLauncher unpack()
diff --git a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
index b20e81e..be91c48 100644
--- a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
+++ b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
@@ -21,6 +21,7 @@ package testng.suiteXml;
import org.testng.annotations.Test;
+import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -29,14 +30,16 @@ import java.util.concurrent.atomic.AtomicInteger;
* @since 2.19
*/
public class TestNGSuiteTest {
- private static final AtomicInteger counter = new AtomicInteger();
+ private static final AtomicInteger COUNTER = new AtomicInteger();
@Test
public void shouldRunAndPrintItself()
throws Exception
{
- System.out.println( getClass().getSimpleName() + "#shouldRunAndPrintItself() "
- + counter.incrementAndGet() + ".");
+ System.out.println( getClass().getSimpleName()
+ + "#shouldRunAndPrintItself() "
+ + COUNTER.incrementAndGet()
+ + "." );
TimeUnit.SECONDS.sleep( 2 );
}