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.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1440882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2013-01-31 09:02:08 +00:00
parent 7af430e071
commit 264437292e
2 changed files with 27 additions and 3 deletions

View File

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

View File

@ -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,7 +70,22 @@ 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() {