Skip to content

Commit 9d389b6

Browse files
committed
Test: add setting to change request timeout for rest client (#25201)
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
1 parent 160d069 commit 9d389b6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
2323
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
2424
import org.apache.lucene.util.TimeUnits;
25+
import org.elasticsearch.common.settings.Settings;
26+
import org.elasticsearch.test.rest.ESRestTestCase;
2527
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
2628
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
2729

@@ -47,6 +49,15 @@ public static Iterable<Object[]> parameters() throws Exception {
4749
return createParameters();
4850
}
4951

52+
@Override
53+
protected Settings restClientSettings() {
54+
return Settings.builder().put(super.restClientSettings())
55+
// increase the timeout so that we can actually see the result of failed cluster health
56+
// calls that have a default timeout of 30s
57+
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "40s")
58+
.build();
59+
}
60+
5061
@Override
5162
protected boolean randomizeContentType() {
5263
return false;

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.client.RestClientBuilder;
3333
import org.elasticsearch.common.io.PathUtils;
3434
import org.elasticsearch.common.settings.Settings;
35+
import org.elasticsearch.common.unit.TimeValue;
3536
import org.elasticsearch.common.util.concurrent.ThreadContext;
3637
import org.elasticsearch.common.xcontent.XContentParser;
3738
import org.elasticsearch.common.xcontent.XContentType;
@@ -67,6 +68,7 @@
6768
public abstract class ESRestTestCase extends ESTestCase {
6869
public static final String TRUSTSTORE_PATH = "truststore.path";
6970
public static final String TRUSTSTORE_PASSWORD = "truststore.password";
71+
public static final String CLIENT_RETRY_TIMEOUT = "client.retry.timeout";
7072

7173
/**
7274
* Convert the entity from a {@link Response} into a map of maps.
@@ -338,6 +340,12 @@ private RestClient buildClient(Settings settings) throws IOException {
338340
}
339341
builder.setDefaultHeaders(defaultHeaders);
340342
}
343+
344+
final String requestTimeoutString = settings.get(CLIENT_RETRY_TIMEOUT);
345+
if (requestTimeoutString != null) {
346+
final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT);
347+
builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis()));
348+
}
341349
return builder.build();
342350
}
343351

0 commit comments

Comments
 (0)