forked from mdodsworth/lucene-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LUCENE-4160: Bring back the functional equivalent of tests.iters.min.…
… Added two properties: -Dtests.maxfailures=M and -Dtests.failfast=[true/false/yes/no/on/off] which control skipping tests after the first M failures have been hit or after the first failure (failfast is an alias for tests.maxfailures=1). git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/branch_4x@1355278 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
7 changed files
with
234 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lucene/core/src/test/org/apache/lucene/util/TestMaxFailuresRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.apache.lucene.util; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.apache.lucene.util.junitcompat.WithNestedTests; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.*; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunListener; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Repeat; | ||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesInvariantRule; | ||
|
||
/** | ||
* @see TestRuleIgnoreAfterMaxFailures | ||
* @see SystemPropertiesInvariantRule | ||
*/ | ||
public class TestMaxFailuresRule extends WithNestedTests { | ||
public TestMaxFailuresRule() { | ||
super(true); | ||
} | ||
|
||
public static class Nested extends WithNestedTests.AbstractNestedTest { | ||
@Repeat(iterations = 100) | ||
public void testFailSometimes() { | ||
assertFalse(random().nextInt(5) == 0); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMaxFailures() { | ||
int maxFailures = LuceneTestCase.ignoreAfterMaxFailures.getMaxFailures(); | ||
try { | ||
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(2); | ||
|
||
JUnitCore core = new JUnitCore(); | ||
final int [] assumptions = new int [1]; | ||
core.addListener(new RunListener() { | ||
@Override | ||
public void testAssumptionFailure(Failure failure) { | ||
assumptions[0]++; | ||
} | ||
}); | ||
|
||
Result result = core.run(Nested.class); | ||
Assert.assertEquals(2, result.getFailureCount()); | ||
Assert.assertEquals(0, result.getIgnoreCount()); | ||
Assert.assertEquals(100, result.getRunCount()); | ||
// JUnit doesn't pass back the number of successful tests, just make sure | ||
// we did have enough assumption-failures. | ||
Assert.assertTrue(assumptions[0] > 50); | ||
} finally { | ||
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(maxFailures); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
lucene/test-framework/src/java/org/apache/lucene/util/TestRuleIgnoreAfterMaxFailures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.apache.lucene.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.internal.AssumptionViolatedException; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import com.carrotsearch.randomizedtesting.RandomizedTest; | ||
import com.carrotsearch.randomizedtesting.annotations.Repeat; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* This rule keeps a count of failed tests (suites) and will result in an | ||
* {@link AssumptionViolatedException} after a given number of failures for all | ||
* tests following this condition. | ||
* | ||
* <p> | ||
* Aborting quickly on failed tests can be useful when used in combination with | ||
* test repeats (via the {@link Repeat} annotation or system property). | ||
*/ | ||
public final class TestRuleIgnoreAfterMaxFailures implements TestRule { | ||
/** | ||
* Maximum failures. | ||
*/ | ||
private int maxFailures; | ||
|
||
/** | ||
* Current count of failures. | ||
*/ | ||
private int failuresSoFar; | ||
|
||
/** | ||
* @param maxFailures | ||
* The number of failures after which all tests are ignored. Must be | ||
* greater or equal 1. | ||
*/ | ||
public TestRuleIgnoreAfterMaxFailures(int maxFailures) { | ||
Assert.assertTrue("maxFailures must be >= 1: " + maxFailures, maxFailures >= 1); | ||
this.maxFailures = maxFailures; | ||
} | ||
|
||
@Override | ||
public Statement apply(final Statement s, final Description d) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
if (failuresSoFar >= maxFailures) { | ||
RandomizedTest.assumeTrue("Ignored, failures limit reached (" + | ||
failuresSoFar + " >= " + maxFailures + ").", false); | ||
} | ||
|
||
try { | ||
s.evaluate(); | ||
} catch (Throwable t) { | ||
if (!TestRuleMarkFailure.isAssumption(t)) { | ||
System.out.println("#" + d); | ||
failuresSoFar++; | ||
} | ||
throw t; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/** For tests only. */ | ||
void setMaxFailures(int maxFailures) { | ||
this.maxFailures = maxFailures; | ||
} | ||
|
||
int getMaxFailures() { | ||
return maxFailures; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
lucene/test-framework/src/java/org/apache/lucene/util/TestRuleIgnoreTestSuites.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters