Zen2: Add test that checks that CoordinatorTests are reproducible (#37225)
Ensures reproducibility of the tests in CoordinatorTests.
This commit is contained in:
parent
0a40564068
commit
9040a96daf
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.cluster.coordination;
|
package org.elasticsearch.cluster.coordination;
|
||||||
|
|
||||||
|
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||||
import org.apache.logging.log4j.CloseableThreadContext;
|
import org.apache.logging.log4j.CloseableThreadContext;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -70,6 +71,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -128,6 +130,24 @@ public class CoordinatorTests extends ESTestCase {
|
||||||
resetPortCounter();
|
resetPortCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check that runRandomly leads to reproducible results
|
||||||
|
public void testRepeatableTests() throws Exception {
|
||||||
|
final Callable<Long> test = () -> {
|
||||||
|
final Cluster cluster = new Cluster(randomIntBetween(1, 5));
|
||||||
|
cluster.runRandomly();
|
||||||
|
final long afterRunRandomly = value(cluster.getAnyNode().getLastAppliedClusterState());
|
||||||
|
cluster.stabilise();
|
||||||
|
final long afterStabilisation = value(cluster.getAnyNode().getLastAppliedClusterState());
|
||||||
|
return afterRunRandomly ^ afterStabilisation;
|
||||||
|
};
|
||||||
|
final long seed = randomLong();
|
||||||
|
logger.info("First run with seed [{}]", seed);
|
||||||
|
final long result1 = RandomizedContext.current().runWithPrivateRandomness(seed, test);
|
||||||
|
logger.info("Second run with seed [{}]", seed);
|
||||||
|
final long result2 = RandomizedContext.current().runWithPrivateRandomness(seed, test);
|
||||||
|
assertEquals(result1, result2);
|
||||||
|
}
|
||||||
|
|
||||||
public void testCanUpdateClusterStateAfterStabilisation() {
|
public void testCanUpdateClusterStateAfterStabilisation() {
|
||||||
final Cluster cluster = new Cluster(randomIntBetween(1, 5));
|
final Cluster cluster = new Cluster(randomIntBetween(1, 5));
|
||||||
cluster.runRandomly();
|
cluster.runRandomly();
|
||||||
|
|
Loading…
Reference in New Issue