mirror of https://github.com/apache/lucene.git
LUCENE-4160: making tests more robust by restoring before-the-test number of failures.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1355263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63eefa822f
commit
b599cdf80f
|
@ -45,9 +45,11 @@ public class TestMaxFailuresRule extends WithNestedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMaxFailures() {
|
public void testMaxFailures() {
|
||||||
int maxFailures = LuceneTestCase.ignoreAfterMaxFailures.getMaxFailures();
|
int maxFailures = LuceneTestCase.ignoreAfterMaxFailures.maxFailures;
|
||||||
|
int failuresSoFar = LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar;
|
||||||
try {
|
try {
|
||||||
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(2);
|
LuceneTestCase.ignoreAfterMaxFailures.maxFailures = 2;
|
||||||
|
LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = 0;
|
||||||
|
|
||||||
JUnitCore core = new JUnitCore();
|
JUnitCore core = new JUnitCore();
|
||||||
final int [] assumptions = new int [1];
|
final int [] assumptions = new int [1];
|
||||||
|
@ -59,14 +61,16 @@ public class TestMaxFailuresRule extends WithNestedTests {
|
||||||
});
|
});
|
||||||
|
|
||||||
Result result = core.run(Nested.class);
|
Result result = core.run(Nested.class);
|
||||||
Assert.assertEquals(2, result.getFailureCount());
|
|
||||||
Assert.assertEquals(0, result.getIgnoreCount());
|
|
||||||
Assert.assertEquals(100, result.getRunCount());
|
Assert.assertEquals(100, 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
|
// JUnit doesn't pass back the number of successful tests, just make sure
|
||||||
// we did have enough assumption-failures.
|
// we did have enough assumption-failures.
|
||||||
Assert.assertTrue(assumptions[0] > 50);
|
Assert.assertTrue(assumptions[0] > 50);
|
||||||
} finally {
|
} finally {
|
||||||
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(maxFailures);
|
LuceneTestCase.ignoreAfterMaxFailures.maxFailures = maxFailures;
|
||||||
|
LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = failuresSoFar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,14 +37,14 @@ import com.carrotsearch.randomizedtesting.annotations.Repeat;
|
||||||
*/
|
*/
|
||||||
public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
|
public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
|
||||||
/**
|
/**
|
||||||
* Maximum failures.
|
* Maximum failures. Package scope for tests.
|
||||||
*/
|
*/
|
||||||
private int maxFailures;
|
int maxFailures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current count of failures.
|
* Current count of failures. Package scope for tests.
|
||||||
*/
|
*/
|
||||||
private int failuresSoFar;
|
int failuresSoFar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param maxFailures
|
* @param maxFailures
|
||||||
|
@ -70,7 +70,6 @@ public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
|
||||||
s.evaluate();
|
s.evaluate();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
if (!TestRuleMarkFailure.isAssumption(t)) {
|
if (!TestRuleMarkFailure.isAssumption(t)) {
|
||||||
System.out.println("#" + d);
|
|
||||||
failuresSoFar++;
|
failuresSoFar++;
|
||||||
}
|
}
|
||||||
throw t;
|
throw t;
|
||||||
|
@ -78,13 +77,4 @@ public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For tests only. */
|
|
||||||
void setMaxFailures(int maxFailures) {
|
|
||||||
this.maxFailures = maxFailures;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getMaxFailures() {
|
|
||||||
return maxFailures;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue