use of com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup in project randomizedtesting by randomizedtesting.
the class ThreadLeakControl method forSuite.
/**
* A {@link Statement} for wrapping suite-level execution.
*/
Statement forSuite(final Statement s, final Description suiteDescription) {
final Class<?> suiteClass = RandomizedContext.current().getTargetClass();
final int timeout = determineTimeout(suiteClass);
return new Statement() {
@Override
public void evaluate() throws Throwable {
checkZombies();
threadLeakGroup = firstAnnotated(ThreadLeakGroup.class, suiteClass, DefaultAnnotationValues.class);
final List<Throwable> errors = new ArrayList<Throwable>();
suiteFilters = instantiateFilters(errors, suiteClass);
MultipleFailureException.assertEmpty(errors);
final StatementRunner sr = new StatementRunner(s);
final boolean timedOut = forkTimeoutingTask(sr, timeout, errors);
synchronized (notifierLock) {
if (timedOut) {
// Mark as timed out so that we don't do any checks in any currently running test
suiteTimedOut.set(true);
// Flush streams so that we don't get warning outputs before sysout buffers.
flushStreams();
// Emit a warning.
LOGGER.warning("Suite execution timed out: " + suiteDescription + formatThreadStacksFull());
// mark subNotifier as dead (no longer passing events).
subNotifier.pleaseStop();
}
}
if (timedOut) {
// complete subNotifier state in case in the middle of a test.
if (subNotifier.testInProgress != null) {
targetNotifier.fireTestFailure(new Failure(subNotifier.testInProgress, RandomizedRunner.augmentStackTrace(emptyStack(new Exception("Test abandoned because suite timeout was reached.")))));
targetNotifier.fireTestFinished(subNotifier.testInProgress);
}
// throw suite failure (timeout).
errors.add(RandomizedRunner.augmentStackTrace(emptyStack(new Exception("Suite timeout exceeded (>= " + timeout + " msec)."))));
}
final AnnotatedElement[] chain = { suiteClass, DefaultAnnotationValues.class };
List<Throwable> threadLeakErrors = timedOut ? new ArrayList<Throwable>() : errors;
checkThreadLeaks(refilter(expectedSuiteState, suiteFilters), threadLeakErrors, LifecycleScope.SUITE, suiteDescription, chain);
processUncaught(errors, runner.handler.getUncaughtAndClear());
MultipleFailureException.assertEmpty(errors);
}
@SuppressForbidden("Legitimate use of syserr.")
private void flushStreams() {
System.out.flush();
System.err.flush();
}
};
}
Aggregations