--- jsr166/src/test/tck/CountedCompleterTest.java 2016/10/15 18:51:12 1.30 +++ jsr166/src/test/tck/CountedCompleterTest.java 2018/07/22 20:23:28 1.37 @@ -5,7 +5,6 @@ */ import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; import java.util.HashSet; import java.util.concurrent.CancellationException; @@ -13,7 +12,6 @@ import java.util.concurrent.CountedCompl import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; -import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -78,7 +76,7 @@ public class CountedCompleterTest extend assertNull(a.getRawResult()); try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -96,7 +94,7 @@ public class CountedCompleterTest extend Thread.currentThread().interrupt(); long startTime = System.nanoTime(); assertNull(a.join()); - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } @@ -104,18 +102,20 @@ public class CountedCompleterTest extend 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)); + + Object v1 = null, v2 = null; try { - assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(a.get(5L, SECONDS)); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(v1); + assertNull(v2); } void checkCancelled(CountedCompleter a) { @@ -139,7 +139,7 @@ public class CountedCompleterTest extend { long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } try { @@ -149,7 +149,7 @@ public class CountedCompleterTest extend } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -177,7 +177,7 @@ public class CountedCompleterTest extend { long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } try { @@ -188,7 +188,7 @@ public class CountedCompleterTest extend } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (ExecutionException success) { assertSame(t.getClass(), success.getCause().getClass()); @@ -211,7 +211,7 @@ public class CountedCompleterTest extend final AtomicInteger onCompletionN = new AtomicInteger(0); final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); final AtomicInteger setRawResultN = new AtomicInteger(0); - final AtomicReference rawResult = new AtomicReference(null); + final AtomicReference rawResult = new AtomicReference<>(null); int computeN() { return computeN.get(); } int onCompletionN() { return onCompletionN.get(); } int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } @@ -703,7 +703,7 @@ public class CountedCompleterTest extend CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -735,6 +735,8 @@ public class CountedCompleterTest extend CCF f = new LCCF(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(21, f.number); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -1425,7 +1427,7 @@ public class CountedCompleterTest extend CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }};