--- jsr166/src/test/tck/JSR166TestCase.java 2015/09/07 17:14:06 1.140 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/09/25 05:41:29 1.145 @@ -67,18 +67,18 @@ import junit.framework.TestSuite; * *
    * - *
  1. All assertions in code running in generated threads must use + *
  2. All assertions in code running in generated threads must use * the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link * #threadAssertEquals}, or {@link #threadAssertNull}, (not * {@code fail}, {@code assertTrue}, etc.) It is OK (but not * particularly recommended) for other code to use these forms too. * Only the most typically used JUnit assertion methods are defined - * this way, but enough to live with.
  3. + * this way, but enough to live with. * - *
  4. If you override {@link #setUp} or {@link #tearDown}, make sure + *
  5. If you override {@link #setUp} or {@link #tearDown}, make sure * to invoke {@code super.setUp} and {@code super.tearDown} within * them. These methods are used to clear and check for thread - * assertion failures.
  6. + * assertion failures. * *
  7. All delays and timeouts must use one of the constants {@code * SHORT_DELAY_MS}, {@code SMALL_DELAY_MS}, {@code MEDIUM_DELAY_MS}, @@ -89,44 +89,44 @@ import junit.framework.TestSuite; * is always discriminable as larger than SHORT and smaller than * MEDIUM. And so on. These constants are set to conservative values, * but even so, if there is ever any doubt, they can all be increased - * in one spot to rerun tests on slower platforms.
  8. + * in one spot to rerun tests on slower platforms. * - *
  9. All threads generated must be joined inside each test case + *
  10. All threads generated must be joined inside each test case * method (or {@code fail} to do so) before returning from the * method. The {@code joinPool} method can be used to do this when - * using Executors.
  11. + * using Executors. * *
* *

Other notes *

*/ @@ -198,14 +198,15 @@ public class JSR166TestCase extends Test } protected void runTestProfiled() throws Throwable { - // Warmup run, notably to trigger all needed classloading. - super.runTest(); - long t0 = System.nanoTime(); - try { + for (int i = 0; i < 2; i++) { + long startTime = System.nanoTime(); super.runTest(); - } finally { - long elapsedMillis = millisElapsedSince(t0); - if (elapsedMillis >= profileThreshold) + long elapsedMillis = millisElapsedSince(startTime); + if (elapsedMillis < profileThreshold) + break; + // Never report first run of any test; treat it as a + // warmup run, notably to trigger all needed classloading, + if (i > 0) System.out.printf("%n%s: %d%n", toString(), elapsedMillis); } } @@ -388,7 +389,7 @@ public class JSR166TestCase extends Test // Java9+ test classes if (atLeastJava9()) { String[] java9TestClassNames = { - // Currently empty + // Currently empty, but expecting varhandle tests }; addNamedTestClasses(suite, java9TestClassNames); } @@ -744,20 +745,20 @@ public class JSR166TestCase extends Test } /** Like Runnable, but with the freedom to throw anything */ - interface Thunk { public void run() throws Throwable; } + interface Action { public void run() throws Throwable; } /** - * Runs all the given tasks in parallel, failing if any fail. + * Runs all the given actions in parallel, failing if any fail. * Useful for running multiple variants of tests that are * necessarily individually slow because they must block. */ - void testInParallel(Thunk ... thunks) { + void testInParallel(Action ... actions) { ExecutorService pool = Executors.newCachedThreadPool(); try { - ArrayList> futures = new ArrayList<>(thunks.length); - for (final Thunk thunk : thunks) + ArrayList> futures = new ArrayList<>(actions.length); + for (final Action action : actions) futures.add(pool.submit(new CheckedRunnable() { - public void realRun() throws Throwable { thunk.run();}})); + public void realRun() throws Throwable { action.run();}})); for (Future future : futures) try { assertNull(future.get(LONG_DELAY_MS, MILLISECONDS)); @@ -1223,7 +1224,10 @@ public class JSR166TestCase extends Test public static final String TEST_STRING = "a test string"; public static class StringTask implements Callable { - public String call() { return TEST_STRING; } + final String value; + public StringTask() { this(TEST_STRING); } + public StringTask(String value) { this.value = value; } + public String call() { return value; } } public Callable latchAwaitingStringTask(final CountDownLatch latch) {