--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 22:20:05 1.157 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/04 00:30:50 1.159 @@ -541,6 +541,7 @@ public class JSR166TestCase extends Test * the same test have no effect. */ public void threadRecordFailure(Throwable t) { + System.err.println(t); dumpTestThreads(); threadFailure.compareAndSet(null, t); } @@ -769,26 +770,37 @@ public class JSR166TestCase extends Test /** * Allows use of try-with-resources with per-test thread pools. */ - static class PoolCloser + class PoolCleaner implements AutoCloseable { public final T pool; - public PoolCloser(T pool) { this.pool = pool; } + public PoolCleaner(T pool) { this.pool = pool; } public void close() { joinPool(pool); } } + PoolCleaner cleaner(T pool) { + return new PoolCleaner(pool); + } + /** * Waits out termination of a thread pool or fails doing so. */ - static void joinPool(ExecutorService pool) { + void joinPool(ExecutorService pool) { try { pool.shutdown(); - if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) - fail("ExecutorService " + pool + - " did not terminate in a timely manner"); + if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) { + try { + threadFail("ExecutorService " + pool + + " did not terminate in a timely manner"); + } finally { + // last resort, for the benefit of subsequent tests + pool.shutdownNow(); + pool.awaitTermination(SMALL_DELAY_MS, MILLISECONDS); + } + } } catch (SecurityException ok) { // Allowed in case test doesn't have privs } catch (InterruptedException fail) { - fail("Unexpected InterruptedException"); + threadFail("Unexpected InterruptedException"); } } @@ -801,9 +813,9 @@ public class JSR166TestCase extends Test * necessarily individually slow because they must block. */ void testInParallel(Action ... actions) { - try (PoolCloser poolCloser - = new PoolCloser<>(Executors.newCachedThreadPool())) { - ExecutorService pool = poolCloser.pool; + try (PoolCleaner cleaner + = cleaner(Executors.newCachedThreadPool())) { + ExecutorService pool = cleaner.pool; ArrayList> futures = new ArrayList<>(actions.length); for (final Action action : actions) futures.add(pool.submit(new CheckedRunnable() { @@ -860,7 +872,7 @@ public class JSR166TestCase extends Test delay(millis); assertTrue(thread.isAlive()); } catch (InterruptedException fail) { - fail("Unexpected InterruptedException"); + threadFail("Unexpected InterruptedException"); } } @@ -882,7 +894,7 @@ public class JSR166TestCase extends Test for (Thread thread : threads) assertTrue(thread.isAlive()); } catch (InterruptedException fail) { - fail("Unexpected InterruptedException"); + threadFail("Unexpected InterruptedException"); } }