Skip to content

Commit 234e7ed

Browse files
authored
Fix RemoteClusterSecurityRestIT by waiting for tasks to finish (#128777)
1 parent 4880245 commit 234e7ed

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,6 @@ tests:
417417
- class: org.elasticsearch.packaging.test.DockerTests
418418
method: test025SyncPluginsUsingProxy
419419
issue: https://github.com/elastic/elasticsearch/issues/127138
420-
- class: org.elasticsearch.xpack.remotecluster.RemoteClusterSecurityRestIT
421-
method: testTaskCancellation
422-
issue: https://github.com/elastic/elasticsearch/issues/128009
423420
- class: org.elasticsearch.xpack.esql.action.CrossClusterQueryWithPartialResultsIT
424421
method: testOneRemoteClusterPartial
425422
issue: https://github.com/elastic/elasticsearch/issues/124055

x-pack/plugin/security/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/remotecluster/RemoteClusterSecurityRestIT.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public void testTaskCancellation() throws Exception {
155155
final String indexName = "index_fulfilling";
156156
final String roleName = "taskCancellationRoleName";
157157
final String userName = "taskCancellationUsername";
158+
String asyncSearchOpaqueId = "async-search-opaque-id-" + randomUUID();
158159
try {
159160
// create some index on the fulfilling cluster, to be searched from the querying cluster
160161
{
@@ -206,13 +207,12 @@ public void testTaskCancellation() throws Exception {
206207
{
207208
"name": "*:*",
208209
"error_type": "exception",
209-
"stall_time_seconds": 60
210+
"stall_time_seconds": 10
210211
}
211212
]
212213
}
213214
}
214215
}""");
215-
String asyncSearchOpaqueId = "async-search-opaque-id-" + randomUUID();
216216
submitAsyncSearchRequest.setOptions(
217217
RequestOptions.DEFAULT.toBuilder()
218218
.addHeader("Authorization", headerFromRandomAuthMethod(userName, PASS))
@@ -308,6 +308,25 @@ public void testTaskCancellation() throws Exception {
308308
assertOK(adminClient().performRequest(new Request("DELETE", "/_security/user/" + userName)));
309309
assertOK(adminClient().performRequest(new Request("DELETE", "/_security/role/" + roleName)));
310310
assertOK(performRequestAgainstFulfillingCluster(new Request("DELETE", indexName)));
311+
// wait for search related tasks to finish on the query cluster
312+
assertBusy(() -> {
313+
try {
314+
Response queryingClusterTasks = adminClient().performRequest(new Request("GET", "/_tasks"));
315+
assertOK(queryingClusterTasks);
316+
Map<String, Object> responseMap = XContentHelper.convertToMap(
317+
JsonXContent.jsonXContent,
318+
EntityUtils.toString(queryingClusterTasks.getEntity()),
319+
false
320+
);
321+
selectTasksWithOpaqueId(responseMap, asyncSearchOpaqueId, task -> {
322+
if (task.get("action") instanceof String action && action.contains("indices:data/read/search")) {
323+
fail("there are still search tasks running");
324+
}
325+
});
326+
} catch (ResponseException e) {
327+
fail(e.getMessage());
328+
}
329+
});
311330
}
312331
}
313332

0 commit comments

Comments
 (0)