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
This commit is contained in:
Robert Muir 2010-12-18 19:43:46 +00:00
parent 623fd7bcd7
commit 50fe69c091
1 changed files with 7 additions and 4 deletions

View File

@ -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);