--- jsr166/src/test/tck/RecursiveTaskTest.java 2015/04/25 04:55:31 1.32 +++ jsr166/src/test/tck/RecursiveTaskTest.java 2017/05/29 19:15:02 1.36 @@ -4,7 +4,7 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.HashSet; import java.util.concurrent.CancellationException; @@ -41,15 +41,13 @@ public class RecursiveTaskTest extends J } private T testInvokeOnPool(ForkJoinPool pool, RecursiveTask a) { - try { + try (PoolCleaner cleaner = cleaner(pool)) { checkNotDone(a); T result = pool.invoke(a); checkCompletedNormally(a, result); return result; - } finally { - joinPool(pool); } } @@ -71,14 +69,14 @@ public class RecursiveTaskTest extends J Thread.currentThread().interrupt(); try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -96,9 +94,7 @@ public class RecursiveTaskTest extends J assertFalse(a.cancel(true)); try { assertSame(expected, a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertSame(expected, a.get(5L, SECONDS)); + assertSame(expected, a.get(randomTimeout(), randomTimeUnit())); } catch (Throwable fail) { threadUnexpectedException(fail); } } @@ -143,7 +139,7 @@ public class RecursiveTaskTest extends J } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -174,7 +170,7 @@ public class RecursiveTaskTest 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()); @@ -185,10 +181,10 @@ public class RecursiveTaskTest extends J public FJException() { super(); } } - // An invalid return value for Fib + /** An invalid return value for Fib. */ static final Integer NoResult = Integer.valueOf(-17); - // A simple recursive task for testing + /** A simple recursive task for testing. */ final class FibTask extends CheckedRecursiveTask { final int number; FibTask(int n) { number = n; } @@ -206,7 +202,7 @@ public class RecursiveTaskTest extends J } } - // A recursive action failing in base case + /** A recursive action failing in base case. */ final class FailingFibTask extends RecursiveTask { final int number; int result; @@ -295,7 +291,7 @@ public class RecursiveTaskTest extends J public Integer realCompute() throws Exception { FibTask f = new FibTask(8); assertSame(f, f.fork()); - Integer r = f.get(5L, SECONDS); + Integer r = f.get(LONG_DELAY_MS, MILLISECONDS); assertEquals(21, (int) r); checkCompletedNormally(f, r); return r; @@ -330,6 +326,8 @@ public class RecursiveTaskTest extends J FibTask f = new FibTask(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f, 21); return NoResult; @@ -419,7 +417,7 @@ public class RecursiveTaskTest extends J FailingFibTask f = new FailingFibTask(8); assertSame(f, f.fork()); try { - Integer r = f.get(5L, SECONDS); + Integer r = f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { Throwable cause = success.getCause(); @@ -516,7 +514,7 @@ public class RecursiveTaskTest extends J assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { - Integer r = f.get(5L, SECONDS); + Integer r = f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (CancellationException success) { checkCancelled(f);