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/04/01 12:03:42 UTC
[maven-surefire] branch master updated: [SUREFIRE-1487]
ParallelComputerBuilderTest fails on overloaded system because internal
delay are shorter than blocking time of JVM
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 882cbb6 [SUREFIRE-1487] ParallelComputerBuilderTest fails on overloaded system because internal delay are shorter than blocking time of JVM
882cbb6 is described below
commit 882cbb62c084442bd2540a0747295f9908e90e63
Author: Tibor17 <ti...@apache.org>
AuthorDate: Sun Apr 1 14:03:22 2018 +0200
[SUREFIRE-1487] ParallelComputerBuilderTest fails on overloaded system because internal delay are shorter than blocking time of JVM
---
.../junitcore/pc/ParallelComputerBuilderTest.java | 95 +++++++++++++---------
.../junitcore/pc/ParallelComputerUtilTest.java | 49 +++++------
2 files changed, 82 insertions(+), 62 deletions(-)
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
index a679563..814456d 100755
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
@@ -59,6 +59,8 @@ import static org.junit.Assert.*;
*/
public class ParallelComputerBuilderTest
{
+ private static final int DELAY_MULTIPLIER = 7;
+
private static final Object class1Lock = new Object();
private static volatile boolean beforeShutdown;
@@ -137,9 +139,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -151,11 +153,11 @@ public class ParallelComputerBuilderTest
assertTrue( result.wasSuccessful() );
if ( Class1.maxConcurrentMethods == 1 )
{
- assertThat( timeSpent, between( 1950, 2250 ) );
+ assertThat( timeSpent, between( 2000 * DELAY_MULTIPLIER - 50, 2250 * DELAY_MULTIPLIER ) );
}
else if ( Class1.maxConcurrentMethods == 2 )
{
- assertThat( timeSpent, between( 1450, 1750 ) );
+ assertThat( timeSpent, between( 1500 * DELAY_MULTIPLIER - 50, 1750 * DELAY_MULTIPLIER ) );
}
else
{
@@ -175,9 +177,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class, Class1.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -188,7 +190,11 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( 5 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 2 ) );
- assertThat( timeSpent, anyOf( between( 1450, 1750 ), between( 1950, 2250 ), between( 2450, 2750 ) ) );
+ assertThat( timeSpent, anyOf(
+ between( 1500 * DELAY_MULTIPLIER - 50, 1750 * DELAY_MULTIPLIER ),
+ between( 2000 * DELAY_MULTIPLIER - 50, 2250 * DELAY_MULTIPLIER ),
+ between( 2500 * DELAY_MULTIPLIER - 50, 2750 * DELAY_MULTIPLIER )
+ ) );
}
@Test
@@ -204,9 +210,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class, Class1.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -217,7 +223,7 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( 8 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 4 ) );
- assertThat( timeSpent, between( 950, 1250 ) );
+ assertThat( timeSpent, between( 1000 * DELAY_MULTIPLIER - 50, 1250 * DELAY_MULTIPLIER ) );
}
@Test
@@ -239,9 +245,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -252,7 +258,7 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( 3 ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 1 ) );
- assertThat( timeSpent, between( 1950, 2250 ) );
+ assertThat( timeSpent, between( 2000 * DELAY_MULTIPLIER - 50, 2250 * DELAY_MULTIPLIER ) );
}
@Test
@@ -266,9 +272,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -279,7 +285,7 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 3 ) );
- assertThat( timeSpent, between( 950, 1250 ) );
+ assertThat( timeSpent, between( 1000 * DELAY_MULTIPLIER - 50, 1250 * DELAY_MULTIPLIER ) );
}
@Test
@@ -296,9 +302,9 @@ public class ParallelComputerBuilderTest
// Each group takes 0.5s.
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class, Class1.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -309,7 +315,7 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 3 ) );
- assertThat( timeSpent, between( 950, 1250 ) );
+ assertThat( timeSpent, between( 1000 * DELAY_MULTIPLIER - 50, 1250 * DELAY_MULTIPLIER ) );
}
@Test
@@ -323,9 +329,9 @@ public class ParallelComputerBuilderTest
ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( computer, TestSuite.class, Class1.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertThat( computer.getSuites().size(), is( 1 ) );
@@ -336,30 +342,30 @@ public class ParallelComputerBuilderTest
assertThat( computer.getPoolCapacity(), is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
assertTrue( result.wasSuccessful() );
assertThat( Class1.maxConcurrentMethods, is( 2 ) );
- assertThat( timeSpent, between( 1450, 1750 ) );
+ assertThat( timeSpent, between( 1500 * DELAY_MULTIPLIER - 50, 1750 * DELAY_MULTIPLIER ) );
}
- @Test( timeout = 2000 )
+ @Test( timeout = 2000 * DELAY_MULTIPLIER )
public void shutdown()
{
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = new ShutdownTest().run( false );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertTrue( result.wasSuccessful() );
assertTrue( beforeShutdown );
- assertThat( timeSpent, between( 450, 1250 ) );
+ assertThat( timeSpent, between( 500 * DELAY_MULTIPLIER - 50, 1250 * DELAY_MULTIPLIER ) );
}
- @Test( timeout = 2000 )
+ @Test( timeout = 2000 * DELAY_MULTIPLIER )
public void shutdownWithInterrupt()
{
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
new ShutdownTest().run( true );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
assertTrue( beforeShutdown );
- assertThat( timeSpent, between( 450, 1250 ) );
+ assertThat( timeSpent, between( 500 * DELAY_MULTIPLIER - 50, 1250 * DELAY_MULTIPLIER ) );
}
@Test
@@ -568,7 +574,7 @@ public class ParallelComputerBuilderTest
for ( int i = 0; i < 5; i++ )
{
System.gc();
- TimeUnit.MILLISECONDS.sleep( 500 );
+ TimeUnit.MILLISECONDS.sleep( 500L );
}
Collection<Thread> expectedThreads = jvmThreads();
ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder( logger );
@@ -580,7 +586,7 @@ public class ParallelComputerBuilderTest
for ( int i = 0; i < 5 && expectedThreads.size() != jvmThreads().size(); i++ )
{
System.gc();
- TimeUnit.MILLISECONDS.sleep( 500 );
+ TimeUnit.MILLISECONDS.sleep( 500L );
}
assertThat( jvmThreads(), is( expectedThreads ) );
}
@@ -643,7 +649,7 @@ public class ParallelComputerBuilderTest
synchronized ( class1Lock )
{
++concurrentMethods;
- class1Lock.wait( 500 );
+ class1Lock.wait( DELAY_MULTIPLIER * 500L );
maxConcurrentMethods = Math.max( maxConcurrentMethods, concurrentMethods-- );
}
}
@@ -744,7 +750,7 @@ public class ParallelComputerBuilderTest
{
private final Class<?> testClass;
private final Description suiteDescription;
- private Description myTestMethodDescr;
+ private final Description myTestMethodDescr;
@SuppressWarnings( "unchecked" )
public ReportOneTestAtRuntimeRunner( Class<?> testClass ) throws InitializationError
@@ -928,7 +934,7 @@ public class ParallelComputerBuilderTest
throws InterruptedException
{
System.out.println( new Date() + " BEG: beforeClass" );
- TimeUnit.SECONDS.sleep( 1 );
+ sleepSeconds( 1 );
System.out.println( new Date() + " END: beforeClass" );
}
@@ -937,7 +943,7 @@ public class ParallelComputerBuilderTest
throws InterruptedException
{
System.out.println( new Date() + " BEG: before" );
- TimeUnit.SECONDS.sleep( 1 );
+ sleepSeconds( 1 );
System.out.println( new Date() + " END: before" );
}
@@ -946,7 +952,7 @@ public class ParallelComputerBuilderTest
throws InterruptedException
{
System.out.println( new Date() + " BEG: test" );
- TimeUnit.SECONDS.sleep( 1 );
+ sleepSeconds( 1 );
System.out.println( new Date() + " END: test" );
}
@@ -955,7 +961,7 @@ public class ParallelComputerBuilderTest
throws InterruptedException
{
System.out.println( new Date() + " BEG: after" );
- TimeUnit.SECONDS.sleep( 1 );
+ sleepSeconds( 1 );
System.out.println( new Date() + " END: after" );
}
@@ -964,8 +970,19 @@ public class ParallelComputerBuilderTest
throws InterruptedException
{
System.out.println( new Date() + " BEG: afterClass" );
- TimeUnit.SECONDS.sleep( 1 );
+ sleepSeconds( 1 );
System.out.println( new Date() + " END: afterClass" );
}
}
+
+ private static long systemMillis()
+ {
+ return TimeUnit.NANOSECONDS.toMillis( System.nanoTime() );
+ }
+
+ private static void sleepSeconds( int seconds )
+ throws InterruptedException
+ {
+ TimeUnit.SECONDS.sleep( seconds );
+ }
}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
index f6c1139..d753705 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtilTest.java
@@ -39,12 +39,10 @@ import org.junit.runner.RunWith;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static org.apache.maven.surefire.junitcore.pc.ParallelComputerUtil.*;
import static org.apache.maven.surefire.junitcore.JUnitCoreParameters.*;
-import static org.apache.maven.surefire.junitcore.pc.RangeMatcher.between;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
@@ -973,9 +971,9 @@ public final class ParallelComputerUtilTest
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( logger, params );
ParallelComputer pc = pcBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
final Result result = core.run( pc, TestClass.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
long timeSpent = t2 - t1;
final long deltaTime = 500L;
@@ -996,14 +994,14 @@ public final class ParallelComputerUtilTest
Map<String, String> properties = new HashMap<String, String>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
- properties.put(PARALLEL_TIMEOUT_KEY, Double.toString(2.5d));
+ properties.put(PARALLEL_TIMEOUT_KEY, Double.toString( 2.5d ));
JUnitCoreParameters params = new JUnitCoreParameters( properties );
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( logger, params );
ParallelComputer pc = pcBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
core.run( pc, TestClass.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
final long deltaTime = 500L;
@@ -1027,9 +1025,9 @@ public final class ParallelComputerUtilTest
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( logger, params );
ParallelComputer pc = pcBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
core.run( pc, TestClass.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
final long deltaTime = 500L;
@@ -1056,9 +1054,9 @@ public final class ParallelComputerUtilTest
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( logger, params );
ParallelComputer pc = pcBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
core.run( pc, TestClass.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
final long deltaTime = 500L;
@@ -1071,21 +1069,21 @@ public final class ParallelComputerUtilTest
@Test
public void forcedTimeoutAndShutdown()
- throws TestSetFailedException, ExecutionException, InterruptedException
+ throws Exception
{
// The JUnitCore returns after 3.5s and the test-methods in TestClass are interrupted after 3.5s.
Map<String, String> properties = new HashMap<String, String>();
properties.put(PARALLEL_KEY, "methods");
properties.put(THREADCOUNTMETHODS_KEY, "2");
- properties.put(PARALLEL_TIMEOUTFORCED_KEY, Double.toString(3.5d));
- properties.put(PARALLEL_TIMEOUT_KEY, Double.toString(4.0d));
+ properties.put(PARALLEL_TIMEOUTFORCED_KEY, Double.toString( 3.5d ) );
+ properties.put(PARALLEL_TIMEOUT_KEY, Double.toString( 4.0d ) );
JUnitCoreParameters params = new JUnitCoreParameters( properties );
ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( logger, params );
ParallelComputer pc = pcBuilder.buildComputer();
final JUnitCore core = new JUnitCore();
- final long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t1 = systemMillis();
core.run( pc, TestClass.class );
- final long t2 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ final long t2 = systemMillis();
final long timeSpent = t2 - t1;
final long deltaTime = 500L;
@@ -1102,14 +1100,14 @@ public final class ParallelComputerUtilTest
public void a()
throws InterruptedException
{
- long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ long t1 = systemMillis();
try
{
Thread.sleep( 5000L );
}
finally
{
- System.out.println( getClass().getSimpleName() + "#a() spent " + ( TimeUnit.NANOSECONDS.toMillis( System.nanoTime()) - t1 ) );
+ System.out.println( getClass().getSimpleName() + "#a() spent " + ( systemMillis() - t1 ) );
}
}
@@ -1117,14 +1115,14 @@ public final class ParallelComputerUtilTest
public void b()
throws InterruptedException
{
- long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ long t1 = systemMillis();
try
{
Thread.sleep( 5000L );
}
finally
{
- System.out.println( getClass().getSimpleName() + "#b() spent " + ( TimeUnit.NANOSECONDS.toMillis( System.nanoTime()) - t1 ) );
+ System.out.println( getClass().getSimpleName() + "#b() spent " + ( systemMillis() - t1 ) );
}
}
@@ -1132,15 +1130,20 @@ public final class ParallelComputerUtilTest
public void c()
throws InterruptedException
{
- long t1 = TimeUnit.NANOSECONDS.toMillis( System.nanoTime());
+ long t1 = systemMillis();
try
{
Thread.sleep( 5000L );
}
finally
{
- System.out.println( getClass().getSimpleName() + "#c() spent " + ( TimeUnit.NANOSECONDS.toMillis( System.nanoTime()) - t1 ) );
+ System.out.println( getClass().getSimpleName() + "#c() spent " + ( systemMillis() - t1 ) );
}
}
}
-}
\ No newline at end of file
+
+ private static long systemMillis()
+ {
+ return TimeUnit.NANOSECONDS.toMillis( System.nanoTime() );
+ }
+}
--
To stop receiving notification emails like this one, please contact
tibordigana@apache.org.