461 |
|
} else { |
462 |
|
return new TestSuite(); |
463 |
|
} |
464 |
– |
|
464 |
|
} |
465 |
|
|
466 |
|
// Delays for timing-dependent tests, in milliseconds. |
518 |
|
* the same test have no effect. |
519 |
|
*/ |
520 |
|
public void threadRecordFailure(Throwable t) { |
521 |
+ |
threadDump(); |
522 |
|
threadFailure.compareAndSet(null, t); |
523 |
|
} |
524 |
|
|
529 |
|
void tearDownFail(String format, Object... args) { |
530 |
|
String msg = toString() + ": " + String.format(format, args); |
531 |
|
System.err.println(msg); |
532 |
< |
printAllStackTraces(); |
532 |
> |
threadDump(); |
533 |
|
throw new AssertionFailedError(msg); |
534 |
|
} |
535 |
|
|
598 |
|
fail(reason); |
599 |
|
} catch (AssertionFailedError t) { |
600 |
|
threadRecordFailure(t); |
601 |
< |
fail(reason); |
601 |
> |
throw t; |
602 |
|
} |
603 |
|
} |
604 |
|
|
778 |
|
* necessarily individually slow because they must block. |
779 |
|
*/ |
780 |
|
void testInParallel(Action ... actions) { |
781 |
< |
ExecutorService pool = Executors.newCachedThreadPool(); |
782 |
< |
try { |
781 |
> |
try (PoolCloser<ExecutorService> poolCloser |
782 |
> |
= new PoolCloser<>(Executors.newCachedThreadPool())) { |
783 |
> |
ExecutorService pool = poolCloser.pool; |
784 |
|
ArrayList<Future<?>> futures = new ArrayList<>(actions.length); |
785 |
|
for (final Action action : actions) |
786 |
|
futures.add(pool.submit(new CheckedRunnable() { |
793 |
|
} catch (Exception ex) { |
794 |
|
threadUnexpectedException(ex); |
795 |
|
} |
795 |
– |
} finally { |
796 |
– |
joinPool(pool); |
796 |
|
} |
797 |
|
} |
798 |
|
|
800 |
|
* A debugging tool to print all stack traces, as jstack does. |
801 |
|
* Uninteresting threads are filtered out. |
802 |
|
*/ |
803 |
< |
static void printAllStackTraces() { |
803 |
> |
static void threadDump() { |
804 |
|
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
805 |
|
System.err.println("------ stacktrace dump start ------"); |
806 |
|
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |