Skip to content

Commit ed76b9a

Browse files
authored
Test: allow setting socket timeout for rest client (#25221)
In #25201, a setting was added to allow setting the retry timeout for the rest client under the impression that this would allow requests to go longer than 30s. However, there is also a socket timeout that needs to be set to greater than 30s, which this change adds a setting for.
1 parent a0fcfc7 commit ed76b9a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected Settings restClientSettings() {
5555
// increase the timeout so that we can actually see the result of failed cluster health
5656
// calls that have a default timeout of 30s
5757
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "40s")
58+
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "40s")
5859
.build();
5960
}
6061
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public abstract class ESRestTestCase extends ESTestCase {
6969
public static final String TRUSTSTORE_PATH = "truststore.path";
7070
public static final String TRUSTSTORE_PASSWORD = "truststore.password";
7171
public static final String CLIENT_RETRY_TIMEOUT = "client.retry.timeout";
72+
public static final String CLIENT_SOCKET_TIMEOUT = "client.socket.timeout";
7273

7374
/**
7475
* Convert the entity from a {@link Response} into a map of maps.
@@ -346,6 +347,11 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
346347
final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT);
347348
builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis()));
348349
}
350+
final String socketTimeoutString = settings.get(CLIENT_SOCKET_TIMEOUT);
351+
if (socketTimeoutString != null) {
352+
final TimeValue socketTimeout = TimeValue.parseTimeValue(socketTimeoutString, CLIENT_SOCKET_TIMEOUT);
353+
builder.setRequestConfigCallback(conf -> conf.setSocketTimeout(Math.toIntExact(socketTimeout.getMillis())));
354+
}
349355
return builder.build();
350356
}
351357

0 commit comments

Comments
 (0)