lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwe...@apache.org
Subject svn commit: r1440882 - in /lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat: TestFailIfDirectoryNotClosed.java WithNestedTests.java
Date Thu, 31 Jan 2013 09:02:08 GMT
Author: dweiss
Date: Thu Jan 31 09:02:08 2013
New Revision: 1440882

URL: http://svn.apache.org/viewvc?rev=1440882&view=rev
Log:
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.

Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java?rev=1440882&r1=1440881&r2=1440882&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestFailIfDirectoryNotClosed.java
Thu Jan 31 09:02:08 2013
@@ -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 TestFailIfDirectoryNotClose
   @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"));
   }
 }

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java?rev=1440882&r1=1440881&r2=1440882&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java
Thu Jan 31 09:02:08 2013
@@ -20,15 +20,20 @@ package org.apache.lucene.util.junitcomp
 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.randomizedtestin
  * 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) {



Mime
View raw message