cardil commented on a change in pull request #112: Adding support for 
externally passed random seed and printing used seed on console
URL: https://github.com/apache/maven-surefire/pull/112#discussion_r195661271
 
 

 ##########
 File path: 
surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
 ##########
 @@ -28,16 +28,23 @@
  * @author <a href="mailto:tibordig...@apache.org";>Tibor Digana (tibor17)</a>
  * @since 2.19
  */
-public class TestNGSuiteTest {
-       private static final AtomicInteger counter = new AtomicInteger();
+public class TestNGSuiteTest
+{
+    private static final AtomicInteger counter = new AtomicInteger();
 
-       @Test
-       public void shouldRunAndPrintItself()
-               throws Exception
-       {
-               System.out.println( getClass().getSimpleName() + 
"#shouldRunAndPrintItself() "
-                                                               + 
counter.incrementAndGet() + ".");
+    @Test
+    public void shouldRunAndPrintItself() throws Exception
+    {
+        String message = String.format(
+                "%s#shouldRunAndPrintItself() %d.",
+                getClass().getSimpleName(),
+                counter.incrementAndGet()
+        );
+        TimeUnit.SECONDS.sleep( 1 );
 
-               TimeUnit.SECONDS.sleep( 2 );
-       }
+        synchronized ( System.out )
 
 Review comment:
   I've explained it in commit message: 
https://github.com/apache/maven-surefire/commit/2beb507001867dc61f2be55d206c5825e9f0c2ca
   
   > Fixing flaky test Surefire1177TestngParallelSuitesIT
   > 
   > This test rely on displaying messages on System.out, but invocations 
wasn't synchronized so messeges tend to interweave and test wasn't able to 
assert for them properly. I added synchronization and move code a litle bit.
   
   Test asserts that messages should be either:
   ```
   TestNGSuiteTest#shouldRunAndPrintItself() 1.
   TestNGSuiteTest#shouldRunAndPrintItself() 2.
   ```
   or 
   ```
   TestNGSuiteTest#shouldRunAndPrintItself() 2.
   TestNGSuiteTest#shouldRunAndPrintItself() 1.
   ```
   
   And without synchronization it often was something like this:
   
   ```
   TestNGSuitTestNGSuiteTeTest#shouldRunAndPrintItself() 1.
   est#shouldRunAndPrintItself() 2.
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to