Skip to content

Apache Lucene open-source search software

LUCENE-4737: be more verbose and print stdout/stderr when a nested test fails. I suspect all these are related to thread leaks on J9 which I cannot reproduce but this should reveal the cause of the problem.

Dawid Weiss264437292e4d
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
index 6ccb95f41f1..09e42e44af4 100644
--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
@@ -22,6 +22,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
public class TestFailIfDirectoryNotClosed extends WithNestedTests {
public TestFailIfDirectoryNotClosed() {
@@ -38,6 +39,10 @@ public class TestFailIfDirectoryNotClosed extends WithNestedTests {
@Test
public void testFailIfDirectoryNotClosed() {
Result r = JUnitCore.runClasses(Nested1.class);
+ for (Failure f : r.getFailures()) {
+ System.out.println("Failure: " + f);
+ }
Assert.assertEquals(1, r.getFailureCount());
+ Assert.assertTrue(r.getFailures().get(0).toString().contains("Resource in scope SUITE failed to close"));
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
index ace8174f600..af3694ad8b8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
@@ -20,15 +20,20 @@ package org.apache.lucene.util.junitcompat;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
+import java.util.List;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestRuleIgnoreTestSuites;
+import org.apache.lucene.util.TestRuleMarkFailure;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
/**
* An abstract test class that prepares nested test classes to run.
@@ -43,7 +48,6 @@ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
* cause havoc (static fields).
*/
public abstract class WithNestedTests {
-
public static abstract class AbstractNestedTest extends LuceneTestCase
implements TestRuleIgnoreTestSuites.NestedTestSuite {
protected static boolean isRunningNested() {
@@ -66,8 +70,23 @@ public abstract class WithNestedTests {
* Restore properties after test.
*/
@Rule
- public SystemPropertiesRestoreRule restoreProperties = new SystemPropertiesRestoreRule();
-
+ public final TestRule rules;
+ {
+ final TestRuleMarkFailure marker = new TestRuleMarkFailure();
+ rules = RuleChain
+ .outerRule(new SystemPropertiesRestoreRule())
+ .around(new TestRuleAdapter() {
+ @Override
+ protected void afterAlways(List<Throwable> errors) throws Throwable {
+ if (marker.hadFailures() && suppressOutputStreams) {
+ System.out.println("sysout from nested test: " + getSysOut() + "\n");
+ System.out.println("syserr from nested test: " + getSysErr());
+ }
+ }
+ })
+ .around(marker);
+ }
+
@Before
public final void before() {
if (suppressOutputStreams) {