Skip to content

Commit

Permalink
Added command-line option for switching zombie thread detection on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Jul 4, 2018
1 parent 5ba04f7 commit a1d31b9
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public class ConsoleTestExecutor {
*/
protected WeakHashMap<Thread, Boolean> threadsRunningBeforeTestExecution = new WeakHashMap<Thread, Boolean>();

/**
* Whether to check for zombie threads at the end of test execution.
*/
protected boolean enableZombieThreadWarning;

/**
* Creates a new instance using the default setup class.
*/
Expand Down Expand Up @@ -156,6 +161,9 @@ public void checkForZombieThreads() {
+ "all threads being started during test execution!");
for (Thread tempThread : tempZombieThreads) {
getStdOut().println(" Thread #" + tempThread.getId() + ": " + tempThread.getName());
for (StackTraceElement tempTraceElement : tempThread.getStackTrace()) {
getStdOut().println(" - " + tempTraceElement);
}
}
}
}
Expand All @@ -174,7 +182,9 @@ public int runWithZombieThreadDetection(String[] someArgs) {
return run(someArgs);
} finally {
// At this point, all threads started by the test run should have finished.
checkForZombieThreads();
if (enableZombieThreadWarning) {
checkForZombieThreads();
}
}
}

Expand Down Expand Up @@ -220,10 +230,15 @@ public int run(String[] someArgs) {
"Sets the seed number to use for the RNG custom operation", "[{--seed} number]");
SimpleCommandLineParser.BooleanOption tempExcludeConsoleStreamsOption = new SimpleCommandLineParser.BooleanOption(
null, "noconsole", "Do not capture stdout & stderr for test XML/HTML output", "[{--noconsole}]");
SimpleCommandLineParser.BooleanOption tempZombieThreadDetectionOption = new SimpleCommandLineParser.BooleanOption(
null, "zombiewarn", "Do warn about threads started during test execution, "
+ "but not terminated until the end (zombie threads)",
"[{--zombiewarn}]");

tempParser.addOptions(tempConsoleOption, tempXmlOption, tempXsltOption, tempNameOption, tempVariantOption,
tempNoremoteOption, tempRemotePortOption, tempRemoteHostOption, tempWaitForPlayOption,
tempSkipModelCheck, tempParameterizedConstantOption, tempSeedOption, tempExcludeConsoleStreamsOption);
tempSkipModelCheck, tempParameterizedConstantOption, tempSeedOption, tempExcludeConsoleStreamsOption,
tempZombieThreadDetectionOption);

if (someArgs.length == 0) {
getStdOut().print(tempParser.getHelp(REMAINING_ARGS_HELP));
Expand All @@ -244,6 +259,8 @@ public int run(String[] someArgs) {
return EXIT_CODE_PARAMETER_ERROR;
}

enableZombieThreadWarning = tempZombieThreadDetectionOption.isSet();

TransformHandling tempTransformHandling = evaluateTransformHandling(tempXsltOption);
String tempExecutionName = tempNameOption.getValue("unnamed");
String tempRootSuiteName = getRootSuiteNameFrom(tempRemainingParameters);
Expand Down

0 comments on commit a1d31b9

Please sign in to comment.