From 264437292e4de92e653547fd1ce877e13f77c505 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Thu, 31 Jan 2013 09:02:08 +0000 Subject: [PATCH] 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 --- .../TestFailIfDirectoryNotClosed.java | 5 ++++ .../util/junitcompat/WithNestedTests.java | 25 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) 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 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) {