From 5ba04f7e392d049ba057a70c9255c3e40af4a215 Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Wed, 4 Jul 2018 14:12:02 +0200 Subject: [PATCH 1/2] Fixed zombie thread detection --- .../de/gebit/integrity/runner/console/ConsoleTestExecutor.java | 2 +- .../src/de/gebit/integrity/runner/forking/Fork.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java index ebc5584fc..2365c8f28 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java @@ -142,7 +142,7 @@ public void checkForZombieThreads() { List tempZombieThreads = new LinkedList(); for (Thread tempThread : tempArray) { - if ((tempThread.getName() != null && tempThread.getName().startsWith("Integrity - ")) + if ((tempThread.getName() != null && !tempThread.getName().startsWith("Integrity - ")) && !threadsRunningBeforeTestExecution.containsKey(tempThread) && tempThread.isAlive() && !tempThread.isDaemon()) { tempZombieThreads.add(tempThread); diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java index 39e96789e..3123a816c 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java @@ -800,6 +800,7 @@ private class FilteringStreamCopier extends Thread { FilteringStreamCopier(String aPrefix, String aThreadName, InputStream aSource, boolean anStdErrFlag, boolean aFilterForHostAndPortFlag) { super(aThreadName); + setDaemon(true); prefix = aPrefix; source = new BufferedReader(new InputStreamReader(aSource)); stdErr = anStdErrFlag; @@ -857,6 +858,7 @@ private class ForkMonitor extends Thread { ForkMonitor() { super("Integrity - Fork Monitor Thread"); + setDaemon(true); } /** From a1d31b9f984b9f0bf9107952fa6abc9f9c05443a Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Wed, 4 Jul 2018 14:38:47 +0200 Subject: [PATCH 2/2] Added command-line option for switching zombie thread detection on/off --- .../runner/console/ConsoleTestExecutor.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java index 2365c8f28..885be0a97 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/console/ConsoleTestExecutor.java @@ -86,6 +86,11 @@ public class ConsoleTestExecutor { */ protected WeakHashMap threadsRunningBeforeTestExecution = new WeakHashMap(); + /** + * Whether to check for zombie threads at the end of test execution. + */ + protected boolean enableZombieThreadWarning; + /** * Creates a new instance using the default setup class. */ @@ -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); + } } } } @@ -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(); + } } } @@ -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)); @@ -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);