--- jsr166/src/test/tck/CountedCompleterTest.java 2015/10/18 19:12:45 1.23 +++ jsr166/src/test/tck/CountedCompleterTest.java 2017/10/26 22:50:07 1.35 @@ -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,10 +110,8 @@ public class CountedCompleterTest extend assertFalse(a.cancel(true)); try { assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(a.get(5L, SECONDS)); - } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(a.get(randomTimeout(), randomTimeUnit())); + } catch (Exception fail) { threadUnexpectedException(fail); } } void checkCancelled(CountedCompleter a) { @@ -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(); } @@ -335,10 +332,15 @@ public class CountedCompleterTest extend public void testSetPendingCount() { NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); - a.setPendingCount(1); - assertEquals(1, a.getPendingCount()); - a.setPendingCount(27); - assertEquals(27, a.getPendingCount()); + int[] vals = { + -1, 0, 1, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + }; + for (int val : vals) { + a.setPendingCount(val); + assertEquals(val, a.getPendingCount()); + } } /** @@ -351,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()); } /** @@ -492,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(); @@ -695,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) {} }}; @@ -727,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); @@ -1417,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) {} }};