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

tibordigana pushed a commit to branch SUREFIRE-1561
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 716e590508b4b9c04399dac20c1b61eefa7f1551
Author: Tibor17 <tibordig...@apache.org>
AuthorDate: Sun Aug 26 12:34:30 2018 +0200

    [SUREFIRE-1561] Logging in Parallel Tests. Integration Test 
Surefire1177TestngParallelSuitesIT permanently fails on Ubuntu
---
 maven-surefire-plugin/src/site/apt/index.apt.vm    |  2 ++
 .../src/site/markdown/parallel-logging.md          | 39 ++++++++++++++++++++++
 maven-surefire-plugin/src/site/site.xml            |  1 +
 .../java/testng/suiteXml/ShouldNotRunTest.java     |  5 ++-
 .../test/java/testng/suiteXml/TestNGSuiteTest.java |  7 ++--
 5 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/maven-surefire-plugin/src/site/apt/index.apt.vm 
b/maven-surefire-plugin/src/site/apt/index.apt.vm
index f7270fc..9a7d448 100644
--- a/maven-surefire-plugin/src/site/apt/index.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/index.apt.vm
@@ -177,4 +177,6 @@ mvn verify
 
   * {{{./docker.html}Run tests in Docker}}
 
+  * {{{./parallel-logging.html}Logger in Parallel Tests}}
+
   []
diff --git a/maven-surefire-plugin/src/site/markdown/parallel-logging.md 
b/maven-surefire-plugin/src/site/markdown/parallel-logging.md
new file mode 100644
index 0000000..c68cd7a
--- /dev/null
+++ b/maven-surefire-plugin/src/site/markdown/parallel-logging.md
@@ -0,0 +1,39 @@
+<!--
+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.
+-->
+
+Safe use of Console and STDOUT STDERR in Parallel Tests
+========================
+
+If you log to standard output, error or console from `parallel` tests you may 
have noticed
+the log messages become mixed up.
+
+To come over this issue, especially on Ubuntu/Linux, synchronize the 
`PrintStream` object.
+You can freely create a `ReportUtility` class embedding this mechanism, but in 
principle
+the synchronization becomes as follows:
+
+```
+    @Test
+    public void shouldRunTest() {
+        synchronized (System.out) {
+            System.out.println(message);
+        }
+        
+        ...
+    }
+```
diff --git a/maven-surefire-plugin/src/site/site.xml 
b/maven-surefire-plugin/src/site/site.xml
index fb60c3b..bd42565 100644
--- a/maven-surefire-plugin/src/site/site.xml
+++ b/maven-surefire-plugin/src/site/site.xml
@@ -60,6 +60,7 @@
       <item name="Shutdown of Forked JVM" href="examples/shutdown.html"/>
       <item name="Run tests with Java 9" href="java9.html"/>
       <item name="Run tests in Docker" href="docker.html"/>
+      <item name="Logger in Parallel Tests" href="parallel-logging.html"/>
     </menu>
   </body>
 </project>
diff --git 
a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
 
b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
index d2eb9ca..4a19e78 100644
--- 
a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
+++ 
b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
@@ -30,6 +30,9 @@ public class ShouldNotRunTest {
     @Test
     public void shouldNotRun()
     {
-        System.out.println( getClass().getSimpleName() + "#shouldNotRun()" );
+        synchronized ( System.out )
+        {
+            System.out.println( getClass().getSimpleName() + "#shouldNotRun()" 
);
+        }
     }
 }
\ No newline at end of file
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..95fe0e2 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
@@ -35,8 +35,11 @@ public class TestNGSuiteTest {
        public void shouldRunAndPrintItself()
                throws Exception
        {
-               System.out.println( getClass().getSimpleName() + 
"#shouldRunAndPrintItself() "
-                                                               + 
counter.incrementAndGet() + ".");
+               synchronized ( System.out )
+               {
+                       System.out.println( getClass().getSimpleName() + 
"#shouldRunAndPrintItself() "
+                                    + counter.incrementAndGet() + ".");
+               }
 
                TimeUnit.SECONDS.sleep( 2 );
        }

Reply via email to