Correcting the test for the pessimistic random seed.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1376390 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-08-23 06:57:10 +00:00
parent 03473400bb
commit 95b22040ca
1 changed files with 26 additions and 8 deletions

View File

@ -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;