Skip to content

Commit c19379e

Browse files
committed
Remove random when using HLRC sync and async calls (#48211)
This commit removes the randomization used by every execute call in the high level rest tests. Previously every execute call, which can be many calls per single test, would rely on a random boolean to determine if they should use the sync or async methods provided to the execute method. This commit runs the tests twice, using two different clusters, both of them providing the value one time via a sysprop. This ensures that the whole suite of tests is run using the sync and async code paths. Closes #39667
1 parent b034153 commit c19379e

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

client/rest-high-level/build.gradle

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.elasticsearch.gradle.test.RestIntegTestTask
2+
13
/*
24
* Licensed to Elasticsearch under one or more contributor
35
* license agreements. See the NOTICE file distributed with
@@ -103,11 +105,22 @@ File nodeTrustStore = file("./testnode.jks")
103105
File pkiTrustCert = file("./src/test/resources/org/elasticsearch/client/security/delegate_pki/testRootCA.crt")
104106

105107
integTest.runner {
108+
systemProperty 'tests.rest.async', 'false'
106109
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')
107110
systemProperty 'tests.rest.cluster.password', System.getProperty('tests.rest.cluster.password', 'test-password')
108111
}
109112

110-
testClusters.integTest {
113+
RestIntegTestTask asyncIntegTest = tasks.create("asyncIntegTest", RestIntegTestTask) {
114+
runner {
115+
systemProperty 'tests.rest.async', 'true'
116+
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')
117+
systemProperty 'tests.rest.cluster.password', System.getProperty('tests.rest.cluster.password', 'test-password')
118+
}
119+
}
120+
121+
check.dependsOn(asyncIntegTest)
122+
123+
testClusters.all {
111124
testDistribution = 'DEFAULT'
112125
systemProperty 'es.scripting.update.ctx_in_params', 'false'
113126
setting 'reindex.remote.whitelist', '[ "[::1]:*", "127.0.0.1:*" ]'
@@ -127,10 +140,10 @@ testClusters.integTest {
127140
setting 'indices.lifecycle.poll_interval', '1000ms'
128141
keystore 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
129142
extraConfigFile 'roles.yml', file('roles.yml')
130-
user username: System.getProperty('tests.rest.cluster.username', 'test_user'),
131-
password: System.getProperty('tests.rest.cluster.password', 'test-password'),
132-
role: System.getProperty('tests.rest.cluster.role', 'admin')
133-
user username: 'admin_user', password: 'admin-password'
143+
user username: System.getProperty('tests.rest.cluster.username', 'test_user'),
144+
password: System.getProperty('tests.rest.cluster.password', 'test-password'),
145+
role: System.getProperty('tests.rest.cluster.role', 'admin')
146+
user username: 'admin_user', password: 'admin-password'
134147

135148
extraConfigFile nodeCert.name, nodeCert
136149
extraConfigFile nodeTrustStore.name, nodeTrustStore

client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.action.search.SearchResponse;
2727
import org.elasticsearch.action.support.PlainActionFuture;
2828
import org.elasticsearch.client.indices.CreateIndexRequest;
29+
import org.elasticsearch.common.Booleans;
2930
import org.elasticsearch.common.bytes.BytesReference;
3031
import org.elasticsearch.common.settings.Settings;
3132
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -52,6 +53,7 @@
5253
public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase {
5354

5455
private static RestHighLevelClient restHighLevelClient;
56+
private static boolean async = Booleans.parseBoolean(System.getProperty("tests.rest.async", "false"));
5557

5658
@Before
5759
public void initHighLevelClient() throws IOException {
@@ -78,20 +80,20 @@ protected static <Req, Resp> Resp execute(Req request, SyncMethod<Req, Resp> syn
7880
AsyncMethod<Req, Resp> asyncMethod) throws IOException {
7981
return execute(request, syncMethod, asyncMethod, RequestOptions.DEFAULT);
8082
}
81-
83+
8284
/**
8385
* Executes the provided request using either the sync method or its async variant, both provided as functions
8486
*/
8587
protected static <Req, Resp> Resp execute(Req request, SyncMethod<Req, Resp> syncMethod,
8688
AsyncMethod<Req, Resp> asyncMethod, RequestOptions options) throws IOException {
87-
if (randomBoolean()) {
89+
if (async == false) {
8890
return syncMethod.execute(request, options);
8991
} else {
9092
PlainActionFuture<Resp> future = PlainActionFuture.newFuture();
9193
asyncMethod.execute(request, options, future);
9294
return future.actionGet();
9395
}
94-
}
96+
}
9597

9698
/**
9799
* Executes the provided request using either the sync method or its async
@@ -100,7 +102,7 @@ protected static <Req, Resp> Resp execute(Req request, SyncMethod<Req, Resp> syn
100102
*/
101103
protected static <Resp> Resp execute(SyncMethodNoRequest<Resp> syncMethodNoRequest, AsyncMethodNoRequest<Resp> asyncMethodNoRequest,
102104
RequestOptions requestOptions) throws IOException {
103-
if (randomBoolean()) {
105+
if (async == false) {
104106
return syncMethodNoRequest.execute(requestOptions);
105107
} else {
106108
PlainActionFuture<Resp> future = PlainActionFuture.newFuture();

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void testGetLicense() throws Exception {
194194
//end::get-license-response
195195

196196
assertThat(currentLicense, containsString("trial"));
197-
assertThat(currentLicense, containsString("integTest"));
197+
assertThat(currentLicense, containsString("ntegTest"));
198198
}
199199
{
200200
GetLicenseRequest request = new GetLicenseRequest();
@@ -233,7 +233,7 @@ public void onFailure(Exception e) {
233233
String currentLicense = response.getLicenseDefinition();
234234
assertThat(currentLicense, startsWith("{"));
235235
assertThat(currentLicense, containsString("trial"));
236-
assertThat(currentLicense, containsString("integTest"));
236+
assertThat(currentLicense, containsString("ntegTest"));
237237
assertThat(currentLicense, endsWith("}"));
238238
}
239239
}

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.elasticsearch.client.indices.CreateIndexRequest;
4949
import org.elasticsearch.cluster.SnapshotsInProgress;
5050
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
51+
import org.elasticsearch.common.Booleans;
5152
import org.elasticsearch.common.settings.Settings;
5253
import org.elasticsearch.common.unit.TimeValue;
5354
import org.elasticsearch.common.xcontent.XContentType;
@@ -457,7 +458,12 @@ public void testSnapshotVerifyRepository() throws IOException {
457458
List<VerifyRepositoryResponse.NodeView> repositoryMetaDataResponse = response.getNodes();
458459
// end::verify-repository-response
459460
assertThat(1, equalTo(repositoryMetaDataResponse.size()));
460-
assertThat("integTest-0", equalTo(repositoryMetaDataResponse.get(0).getName()));
461+
final boolean async = Booleans.parseBoolean(System.getProperty("tests.rest.async", "false"));
462+
if (async) {
463+
assertThat("asyncIntegTest-0", equalTo(repositoryMetaDataResponse.get(0).getName()));
464+
} else {
465+
assertThat("integTest-0", equalTo(repositoryMetaDataResponse.get(0).getName()));
466+
}
461467
}
462468

463469
public void testSnapshotVerifyRepositoryAsync() throws InterruptedException {

modules/transport-netty4/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ TaskProvider<Test> pooledTest = tasks.register("pooledTest", Test) {
6969
systemProperty 'es.set.netty.runtime.available.processors', 'false'
7070
systemProperty 'es.use_unpooled_allocator', 'false'
7171
}
72-
// TODO: we can't use task avoidance here because RestIntegTestTask does the testcluster creation
72+
7373
RestIntegTestTask pooledIntegTest = tasks.create("pooledIntegTest", RestIntegTestTask) {
7474
runner {
7575
systemProperty 'es.set.netty.runtime.available.processors', 'false'

0 commit comments

Comments
 (0)