From 50fe69c091c9fb013b3889f9f717aaaa106a973c Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 18 Dec 2010 19:43:46 +0000 Subject: [PATCH] LUCENE-2819: give rogue-threads left running after the test 1000ms to die naturally before we clear their exception handler and interrupt() them... perhaps they will fail nasty git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1050699 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/org/apache/lucene/util/LuceneTestCase.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java index bf78334aeed..641cf666dd6 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java @@ -469,10 +469,10 @@ public abstract class LuceneTestCase extends Assert { public void tearDown() throws Exception { assertTrue("ensure your setUp() calls super.setUp()!!!", setup); setup = false; - Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler); BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount); if (!getClass().getName().startsWith("org.apache.solr")) threadCleanup("test method: '" + getName() + "'"); + Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler); try { if (!uncaughtExceptions.isEmpty()) { @@ -527,9 +527,7 @@ public abstract class LuceneTestCase extends Assert { for (int i = 0; i < threadCount; i++) { Thread t = stillRunning[i]; - // TODO: turn off our exception handler for these leftover threads... does this work? - if (t != Thread.currentThread()) - t.setUncaughtExceptionHandler(null); + if (t.isAlive() && !rogueThreads.containsKey(t) && t != Thread.currentThread() && @@ -539,7 +537,12 @@ public abstract class LuceneTestCase extends Assert { rogueThreads.put(t, true); shouldFail = true; rogueCount++; + // wait on the thread to die of natural causes + try { + t.join(THREAD_STOP_GRACE_MSEC); + } catch (InterruptedException e) { e.printStackTrace(); } // try to stop the thread: + t.setUncaughtExceptionHandler(null); t.interrupt(); try { t.join(THREAD_STOP_GRACE_MSEC);