From ad547eb7fb304ffa75b9793c34899da38a250cc3 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Mon, 24 Feb 2014 13:46:35 +0100 Subject: [PATCH] Remove nanoTime in global cluster randomization in favor of deriving the seed from the main master seed. Removed shared cluster's seed entirely. The problem here is that if you don't give cluster's seed then test times fluctuate oddly, even for a fixed -Dtests.seed=... This shouldn't be the case -- ideally, the test ran with the same master seed should reproduce pretty much with the same execution time (and internal logic, obviously). From the code point of view "global" variables are indeed a problem because JUnit has no notion of before-suite hooks. And RandomizedRunner doesn't support context accesses in static class initializers (this is intentional because there is no way to determine when such initializers will be executed). A workaround is to move such static global variables to lazily-initialized methods and invoke them (once) in @BeforeClass hooks. --- .../test/ElasticsearchIntegrationTest.java | 18 ++++++++++--- .../org/elasticsearch/test/TestCluster.java | 25 ++++--------------- .../junit/listeners/ReproduceInfoPrinter.java | 18 +------------ .../rest/junit/RestReproduceInfoPrinter.java | 7 +----- .../test/rest/junit/RestTestSuiteRunner.java | 7 +++--- 5 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 004f3edea1d..84d9b0e3fed 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -19,6 +19,8 @@ package org.elasticsearch.test; import com.carrotsearch.hppc.ObjectArrayList; +import com.carrotsearch.randomizedtesting.RandomizedContext; +import com.carrotsearch.randomizedtesting.SeedUtils; import com.google.common.base.Joiner; import org.apache.lucene.util.AbstractRandomizedTest; import org.elasticsearch.ElasticsearchIllegalArgumentException; @@ -64,6 +66,7 @@ import org.elasticsearch.search.SearchService; import org.elasticsearch.test.client.RandomizingClient; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Ignore; import java.io.IOException; @@ -76,7 +79,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; -import static org.elasticsearch.test.TestCluster.SHARED_CLUSTER_SEED; import static org.elasticsearch.test.TestCluster.clusterName; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; @@ -133,7 +135,6 @@ import static org.hamcrest.Matchers.equalTo; * This class supports the following system properties (passed with -Dkey=value to the application) *