Zen2: Add test that checks that CoordinatorTests are reproducible (#37225)

Ensures reproducibility of the tests in CoordinatorTests.
This commit is contained in:
Yannick Welsch 2019-01-09 09:32:24 +01:00 committed by GitHub
parent 0a40564068
commit 9040a96daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.cluster.coordination;
import com.carrotsearch.randomizedtesting.RandomizedContext;
import org.apache.logging.log4j.CloseableThreadContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -70,6 +71,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
@ -128,6 +130,24 @@ public class CoordinatorTests extends ESTestCase {
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() {
final Cluster cluster = new Cluster(randomIntBetween(1, 5));
cluster.runRandomly();