diff --git a/lucene/core/src/test/org/apache/lucene/util/TestMaxFailuresRule.java b/lucene/core/src/test/org/apache/lucene/util/TestMaxFailuresRule.java index bd92eae0e2d..d3f0071c661 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestMaxFailuresRule.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestMaxFailuresRule.java @@ -19,9 +19,9 @@ package org.apache.lucene.util; import org.apache.lucene.util.junitcompat.WithNestedTests; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.Description; import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; @@ -45,7 +45,7 @@ public class TestMaxFailuresRule extends WithNestedTests { } public static class Nested extends WithNestedTests.AbstractNestedTest { - @Repeat(iterations = 100) + @Repeat(iterations = 500) public void testFailSometimes() { assertFalse(random().nextInt(5) == 0); } @@ -61,22 +61,40 @@ public class TestMaxFailuresRule extends WithNestedTests { LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = 0; JUnitCore core = new JUnitCore(); - final int [] assumptions = new int [1]; + final StringBuilder results = new StringBuilder(); core.addListener(new RunListener() { + char lastTest; + + @Override + public void testStarted(Description description) throws Exception { + lastTest = 'S'; // success. + } + @Override public void testAssumptionFailure(Failure failure) { - assumptions[0]++; + lastTest = 'A'; // assumption failure. + } + + @Override + public void testFailure(Failure failure) throws Exception { + lastTest = 'F'; // failure + } + + @Override + public void testFinished(Description description) throws Exception { + results.append(lastTest); } }); Result result = core.run(Nested.class); - Assert.assertEquals(100, result.getRunCount()); + Assert.assertEquals(500, result.getRunCount()); Assert.assertEquals(0, result.getIgnoreCount()); Assert.assertEquals(2, result.getFailureCount()); - // JUnit doesn't pass back the number of successful tests, just make sure - // we did have enough assumption-failures. - Assert.assertTrue(assumptions[0] > 50); + // Make sure we had exactly two failures followed by assumption-failures + // resulting from ignored tests. + Assert.assertTrue(results.toString(), + results.toString().matches("(S*F){2}A+")); } finally { LuceneTestCase.ignoreAfterMaxFailures.maxFailures = maxFailures; LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = failuresSoFar;