You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/12/18 22:47:56 UTC
svn commit: r1050725 -
/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
Author: rmuir
Date: Sat Dec 18 21:47:56 2010
New Revision: 1050725
URL: http://svn.apache.org/viewvc?rev=1050725&view=rev
Log:
LUCENE-2819: print the reproduce-with information when a test leaves threads running (but don't fail yet)
Modified:
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1050725&r1=1050724&r2=1050725&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Sat Dec 18 21:47:56 2010
@@ -336,7 +336,11 @@ public abstract class LuceneTestCase ext
@AfterClass
public static void afterClassLuceneTestCaseJ4() {
- threadCleanup("test class");
+ int rogueThreads = threadCleanup("test class");
+ if (rogueThreads > 0) {
+ // TODO: fail here once the leaks are fixed.
+ System.err.println("RESOURCE LEAK: test class left " + rogueThreads + " thread(s) running");
+ }
String codecDescription;
CodecProvider cp = CodecProvider.getDefault();
@@ -470,8 +474,17 @@ public abstract class LuceneTestCase ext
assertTrue("ensure your setUp() calls super.setUp()!!!", setup);
setup = false;
BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);
- if (!getClass().getName().startsWith("org.apache.solr"))
- threadCleanup("test method: '" + getName() + "'");
+ if (!getClass().getName().startsWith("org.apache.solr")) {
+ int rogueThreads = threadCleanup("test method: '" + getName() + "'");
+ if (rogueThreads > 0) {
+ System.err.println("RESOURCE LEAK: test method: '" + getName()
+ + "' left " + rogueThreads + " thread(s) running");
+ // TODO: fail, but print seed for now.
+ if (!testsFailed && uncaughtExceptions.isEmpty()) {
+ reportAdditionalFailureInfo();
+ }
+ }
+ }
Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler);
try {
@@ -509,10 +522,12 @@ public abstract class LuceneTestCase ext
// jvm-wide list of 'rogue threads' we found, so they only get reported once.
private final static IdentityHashMap<Thread,Boolean> rogueThreads = new IdentityHashMap<Thread,Boolean>();
- private static void threadCleanup(String context) {
- // we will only actually fail() after all cleanup has happened!
- boolean shouldFail = false;
-
+ /**
+ * Looks for leftover running threads, trying to kill them off,
+ * so they don't fail future tests.
+ * returns the number of rogue threads that it found.
+ */
+ private static int threadCleanup(String context) {
// educated guess
Thread[] stillRunning = new Thread[Thread.activeCount()+1];
int threadCount = 0;
@@ -535,7 +550,6 @@ public abstract class LuceneTestCase ext
!t.getName().equals("TimeLimitedCollector timer thread")) {
System.err.println("WARNING: " + context + " left thread running: " + t);
rogueThreads.put(t, true);
- shouldFail = true;
rogueCount++;
// wait on the thread to die of natural causes
try {
@@ -551,12 +565,7 @@ public abstract class LuceneTestCase ext
}
}
}
-
- if (shouldFail && !testsFailed /* don't be loud if the test failed, maybe it didnt join() etc */) {
- // TODO: we can't fail until we fix contrib and solr
- //fail("test '" + getName() + "' left " + rogueCount + " thread(s) running");
- System.err.println("RESOURCE LEAK: " + context + " left " + rogueCount + " thread(s) running");
- }
+ return rogueCount;
}
/**