--- jsr166/src/test/tck/CountedCompleterTest.java 2015/10/18 19:22:36 1.25 +++ jsr166/src/test/tck/CountedCompleterTest.java 2017/11/08 02:26:14 1.36 @@ -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; @@ -77,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); } @@ -95,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(); } @@ -103,7 +102,7 @@ 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(); } @@ -111,9 +110,7 @@ public class CountedCompleterTest extend assertFalse(a.cancel(true)); try { assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(a.get(5L, SECONDS)); + assertNull(a.get(randomTimeout(), randomTimeUnit())); } catch (Throwable fail) { threadUnexpectedException(fail); } } @@ -138,7 +135,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 { @@ -148,7 +145,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); } @@ -176,7 +173,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 { @@ -187,7 +184,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()); @@ -210,7 +207,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(); } @@ -356,6 +353,8 @@ public class CountedCompleterTest extend assertEquals(1, a.getPendingCount()); a.addToPendingCount(27); assertEquals(28, a.getPendingCount()); + a.addToPendingCount(-28); + assertEquals(0, a.getPendingCount()); } /** @@ -497,7 +496,7 @@ public class CountedCompleterTest extend } /** - * quietlyCompleteRoot completes root task + * quietlyCompleteRoot completes root task and only root task */ public void testQuietlyCompleteRoot() { NoopCC a = new NoopCC(); @@ -700,7 +699,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) {} }}; @@ -732,6 +731,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); @@ -1422,7 +1423,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) {} }};