--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/04 18:40:57 1.164 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/08 22:39:57 1.170 @@ -188,7 +188,9 @@ public class JSR166TestCase extends Test return (regex == null) ? null : Pattern.compile(regex); } + // Instrumentation to debug very rare, but very annoying hung test runs. static volatile TestCase currentTestCase; + static volatile int currentRun = 0; static { Runnable checkForWedgedTest = new Runnable() { public void run() { // avoid spurious reports with enormous runsPerTest @@ -197,10 +199,17 @@ public class JSR166TestCase extends Test try { MINUTES.sleep(timeoutMinutes); } catch (InterruptedException unexpected) { break; } if (lastTestCase == currentTestCase) { + System.err.printf( + "Looks like we're stuck running test: %s (%d/%d)%n", + lastTestCase, currentRun, runsPerTest); System.err.println ("Looks like we're stuck running test: " - + lastTestCase); + + lastTestCase + " (" + currentRun + "/" + runsPerTest + ")"); + System.err.println("availableProcessors=" + + Runtime.getRuntime().availableProcessors()); dumpTestThreads(); + // one stack dump is probably enough; more would be spam + break; } lastTestCase = currentTestCase; }}}; @@ -218,6 +227,7 @@ public class JSR166TestCase extends Test protected void runTest() throws Throwable { for (int i = 0; i < runsPerTest; i++) { + currentRun = i; if (profileTests) runTestProfiled(); else @@ -774,10 +784,43 @@ public class JSR166TestCase extends Test public void close() { joinPool(pool); } } + /** + * An extension of PoolCleaner that has an action to release the pool. + */ + class PoolCleanerWithReleaser extends PoolCleaner { + private final Runnable releaser; + public PoolCleanerWithReleaser(ExecutorService pool, Runnable releaser) { + super(pool); + this.releaser = releaser; + } + public void close() { + try { + releaser.run(); + } finally { + super.close(); + } + } + } + PoolCleaner cleaner(ExecutorService pool) { return new PoolCleaner(pool); } + PoolCleaner cleaner(ExecutorService pool, Runnable releaser) { + return new PoolCleanerWithReleaser(pool, releaser); + } + + PoolCleaner cleaner(ExecutorService pool, CountDownLatch latch) { + return new PoolCleanerWithReleaser(pool, releaser(latch)); + } + + Runnable releaser(final CountDownLatch latch) { + return new Runnable() { public void run() { + do { latch.countDown(); } + while (latch.getCount() > 0); + }}; + } + /** * Waits out termination of a thread pool or fails doing so. */ @@ -791,7 +834,7 @@ public class JSR166TestCase extends Test } finally { // last resort, for the benefit of subsequent tests pool.shutdownNow(); - pool.awaitTermination(SMALL_DELAY_MS, MILLISECONDS); + pool.awaitTermination(MEDIUM_DELAY_MS, MILLISECONDS); } } } catch (SecurityException ok) { @@ -1168,7 +1211,7 @@ public class JSR166TestCase extends Test } finally { if (t.getState() != Thread.State.TERMINATED) { t.interrupt(); - fail("Test timed out"); + threadFail("Test timed out"); } } }