--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 19:19:01 1.151 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 22:20:05 1.157 @@ -7,6 +7,7 @@ */ import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.NANOSECONDS; import java.io.ByteArrayInputStream; @@ -187,7 +188,29 @@ public class JSR166TestCase extends Test return (regex == null) ? null : Pattern.compile(regex); } + static volatile TestCase currentTestCase; + static { + Runnable checkForWedgedTest = new Runnable() { public void run() { + // avoid spurious reports with enormous runsPerTest + final int timeoutMinutes = Math.max(runsPerTest / 10, 1); + for (TestCase lastTestCase = currentTestCase;;) { + try { MINUTES.sleep(timeoutMinutes); } + catch (InterruptedException unexpected) { break; } + if (lastTestCase == currentTestCase) { + System.err.println + ("Looks like we're stuck running test: " + + lastTestCase); + dumpTestThreads(); + } + lastTestCase = currentTestCase; + }}}; + Thread thread = new Thread(checkForWedgedTest, "checkForWedgedTest"); + thread.setDaemon(true); + thread.start(); + } + public void runBare() throws Throwable { + currentTestCase = this; if (methodFilter == null || methodFilter.matcher(toString()).find()) super.runBare(); @@ -461,7 +484,6 @@ public class JSR166TestCase extends Test } else { return new TestSuite(); } - } // Delays for timing-dependent tests, in milliseconds. @@ -519,6 +541,7 @@ public class JSR166TestCase extends Test * the same test have no effect. */ public void threadRecordFailure(Throwable t) { + dumpTestThreads(); threadFailure.compareAndSet(null, t); } @@ -529,7 +552,7 @@ public class JSR166TestCase extends Test void tearDownFail(String format, Object... args) { String msg = toString() + ": " + String.format(format, args); System.err.println(msg); - printAllStackTraces(); + dumpTestThreads(); throw new AssertionFailedError(msg); } @@ -598,7 +621,7 @@ public class JSR166TestCase extends Test fail(reason); } catch (AssertionFailedError t) { threadRecordFailure(t); - fail(reason); + throw t; } } @@ -797,10 +820,10 @@ public class JSR166TestCase extends Test } /** - * A debugging tool to print all stack traces, as jstack does. + * A debugging tool to print stack traces of most threads, as jstack does. * Uninteresting threads are filtered out. */ - static void printAllStackTraces() { + static void dumpTestThreads() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); System.err.println("------ stacktrace dump start ------"); for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { @@ -813,6 +836,8 @@ public class JSR166TestCase extends Test if ("Finalizer".equals(name) && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) continue; + if ("checkForWedgedTest".equals(name)) + continue; System.err.print(info); } System.err.println("------ stacktrace dump end ------");