--- jsr166/src/test/tck/ForkJoinTask8Test.java 2017/03/18 20:42:20 1.28 +++ jsr166/src/test/tck/ForkJoinTask8Test.java 2019/08/12 15:08:44 1.34 @@ -5,7 +5,6 @@ */ import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; import java.util.Arrays; import java.util.concurrent.CountDownLatch; @@ -104,7 +103,7 @@ public class ForkJoinTask8Test extends J ((BinaryAsyncAction)a).getForkJoinTaskTag()); try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -114,13 +113,13 @@ public class ForkJoinTask8Test extends J checkCompletedNormally(a, null); } - void checkCompletedNormally(ForkJoinTask a, T expected) { + void checkCompletedNormally(ForkJoinTask a, T expectedValue) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertTrue(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); assertNull(a.getException()); - assertSame(expected, a.getRawResult()); + assertSame(expectedValue, a.getRawResult()); if (a instanceof BinaryAsyncAction) assertEquals(COMPLETE_STATE, ((BinaryAsyncAction)a).getForkJoinTaskTag()); @@ -128,8 +127,8 @@ public class ForkJoinTask8Test extends J { Thread.currentThread().interrupt(); long startTime = System.nanoTime(); - assertSame(expected, a.join()); - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertSame(expectedValue, a.join()); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } @@ -137,18 +136,20 @@ public class ForkJoinTask8Test extends J Thread.currentThread().interrupt(); long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); + + T v1 = null, v2 = null; try { - assertSame(expected, a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertSame(expected, a.get(5L, SECONDS)); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertSame(expectedValue, v1); + assertSame(expectedValue, v2); } void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { @@ -175,7 +176,7 @@ public class ForkJoinTask8Test extends J { long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } try { @@ -186,7 +187,7 @@ public class ForkJoinTask8Test extends J } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (ExecutionException success) { assertSame(t.getClass(), success.getCause().getClass()); @@ -488,7 +489,7 @@ public class ForkJoinTask8Test extends J AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -531,6 +532,8 @@ public class ForkJoinTask8Test extends J AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(0, getQueuedTaskCount()); f.checkCompletedNormally(); }}; @@ -872,14 +875,13 @@ public class ForkJoinTask8Test extends J RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { AsyncFib nul = null; - Runnable[] throwingActions = { + assertThrows( + NullPointerException.class, () -> invokeAll(nul), () -> invokeAll(nul, nul), () -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul), () -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)), - () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)), - }; - assertThrows(NullPointerException.class, throwingActions); + () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9))); }}; testInvokeOnPool(pool, a); }