Author: dfabulich
Date: Sun Nov 25 13:24:00 2007
New Revision: 598058
URL: http://svn.apache.org/viewvc?rev=598058&view=rev
Log:
[SUREFIRE-392] testng parallel test failed non-deterministically. fixed thread
safety bug in the test; slapped synchronized keyword all over the
ReporterManager
Modified:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/TestNGTest.java
Modified:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java?rev=598058&r1=598057&r2=598058&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
(original)
+++
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
Sun Nov 25 13:24:00 2007
@@ -104,7 +104,7 @@
return reports;
}
- public void writeMessage( String message )
+ public synchronized void writeMessage( String message )
{
for ( Iterator i = reports.iterator(); i.hasNext(); )
{
@@ -118,7 +118,7 @@
// Run
// ----------------------------------------------------------------------
- public void runStarting( int testCount )
+ public synchronized void runStarting( int testCount )
{
if ( testCount < 0 )
{
@@ -133,7 +133,7 @@
}
}
- public void runStopped()
+ public synchronized void runStopped()
{
for ( Iterator it = reports.iterator(); it.hasNext(); )
{
@@ -143,7 +143,7 @@
}
}
- public void runAborted( ReportEntry report )
+ public synchronized void runAborted( ReportEntry report )
{
if ( report == null )
{
@@ -160,7 +160,7 @@
++errors;
}
- public void runCompleted()
+ public synchronized void runCompleted()
{
for ( Iterator it = reports.iterator(); it.hasNext(); )
{
@@ -195,7 +195,7 @@
writeFooter( "" );
}
- private void writeFooter( String footer )
+ private synchronized void writeFooter( String footer )
{
for ( Iterator i = reports.iterator(); i.hasNext(); )
{
@@ -209,7 +209,7 @@
private ByteArrayOutputStream stdErr;
- public void testSetStarting( ReportEntry report )
+ public synchronized void testSetStarting( ReportEntry report )
throws ReporterException
{
for ( Iterator it = reports.iterator(); it.hasNext(); )
@@ -220,7 +220,7 @@
}
}
- public void testSetCompleted( ReportEntry report )
+ public synchronized void testSetCompleted( ReportEntry report )
{
if ( !reports.isEmpty() )
{
@@ -251,7 +251,7 @@
}
}
- public void testSetAborted( ReportEntry report )
+ public synchronized void testSetAborted( ReportEntry report )
{
for ( Iterator it = reports.iterator(); it.hasNext(); )
{
@@ -267,7 +267,7 @@
// Test
// ----------------------------------------------------------------------
- public void testStarting( ReportEntry report )
+ public synchronized void testStarting( ReportEntry report )
{
stdOut = new ByteArrayOutputStream();
@@ -295,7 +295,7 @@
}
}
- public void testSucceeded( ReportEntry report )
+ public synchronized void testSucceeded( ReportEntry report )
{
resetStreams();
@@ -307,17 +307,17 @@
}
}
- public void testError( ReportEntry reportEntry )
+ public synchronized void testError( ReportEntry reportEntry )
{
testFailed( reportEntry, "error" );
}
- public void testFailed( ReportEntry reportEntry )
+ public synchronized void testFailed( ReportEntry reportEntry )
{
testFailed( reportEntry, "failure" );
}
- private void testFailed( ReportEntry reportEntry, String typeError )
+ private synchronized void testFailed( ReportEntry reportEntry, String
typeError )
{
// Note that the fields can be null if the test hasn't even started
yet (an early error)
String stdOutLog = stdOut != null ? stdOut.toString() : "";
@@ -357,7 +357,7 @@
IOUtil.close( newErr );
}
- public void reset()
+ public synchronized void reset()
{
for ( Iterator it = reports.iterator(); it.hasNext(); )
{
@@ -386,7 +386,7 @@
return completedCount;
}
- public void testSkipped( ReportEntry report )
+ public synchronized void testSkipped( ReportEntry report )
{
resetStreams();
Modified:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/TestNGTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/TestNGTest.java?rev=598058&r1=598057&r2=598058&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/TestNGTest.java
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-group-thread-parallel/src/test/java/TestNGTest.java
Sun Nov 25 13:24:00 2007
@@ -34,12 +34,16 @@
@Test(groups = {"functional", "notincluded"})
public void test1() throws InterruptedException
{
- m_testCount++;
+ incrementTestCount();
System.out.println("running test");
Assert.assertTrue( testObject != null , "testObject is null" );
waitForTestCountToBeThree();
}
+ private synchronized void incrementTestCount() {
+ m_testCount++;
+ }
+
@Test(groups = {"functional", "notincluded"})
public void test2() throws InterruptedException {
test1();
@@ -55,7 +59,7 @@
{
if ( m_testCount == 3 ) return;
long now = System.currentTimeMillis();
- long timeout = 1 * 1000;
+ long timeout = 5 * 1000;
long finish = now + timeout;
while ( m_testCount < 3 && System.currentTimeMillis() < finish )
{