From fdd045db7b39e89a237f13a7a9f38b53bab4ab72 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 13 Jun 2017 09:07:25 -0600 Subject: [PATCH] Test: add setting to change request timeout for rest client This commit adds a setting to change the request timeout for the rest client. This is useful as the default timeout is 30s, which is also the same default for calls like cluster health. If both are the same then the response from the cluster health api will not be received as the client usually times out first making test failures harder to debug. Relates #25185 --- .../upgrades/UpgradeClusterClientYamlTestSuiteIT.java | 11 +++++++++++ .../org/elasticsearch/test/rest/ESRestTestCase.java | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java index 34c27454ec54f..2977e783cf60d 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java @@ -22,6 +22,8 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import org.apache.lucene.util.TimeUnits; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; @@ -46,5 +48,14 @@ public UpgradeClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate public static Iterable parameters() throws Exception { return createParameters(); } + + @Override + protected Settings restClientSettings() { + return Settings.builder().put(super.restClientSettings()) + // increase the timeout so that we can actually see the result of failed cluster health + // calls that have a default timeout of 30s + .put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "40s") + .build(); + } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index a2d6f3bea5cc4..ce10c6315067b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -32,6 +32,7 @@ import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; @@ -67,6 +68,7 @@ public abstract class ESRestTestCase extends ESTestCase { public static final String TRUSTSTORE_PATH = "truststore.path"; public static final String TRUSTSTORE_PASSWORD = "truststore.password"; + public static final String CLIENT_RETRY_TIMEOUT = "client.retry.timeout"; /** * Convert the entity from a {@link Response} into a map of maps. @@ -338,6 +340,12 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE } builder.setDefaultHeaders(defaultHeaders); } + + final String requestTimeoutString = settings.get(CLIENT_RETRY_TIMEOUT); + if (requestTimeoutString != null) { + final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT); + builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis())); + } return builder.build(); }