Skip to content

Commit a5fb837

Browse files
committed
Wait for search tasks to disappear before test finishes
1 parent 71c8aea commit a5fb837

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,16 +1369,13 @@ private static void wipeClusterSettings() throws IOException {
13691369

13701370
if (mustClear.get()) {
13711371
request.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(warnings -> {
1372-
for (String warning : warnings) {
1373-
if (warning.contains("xpack.monitoring")) {
1374-
SUITE_LOGGER.warn("Ignoring xpack monitoring warning during test cleanup: {}", warning);
1375-
} else if (warning.contains("name begins with a dot")) {
1376-
SUITE_LOGGER.warn("Ignoring dot prefix warning during test cleanup: {}", warning);
1377-
} else {
1378-
return true;
1379-
}
1372+
if (warnings.isEmpty()) {
1373+
return false;
1374+
} else if (warnings.size() > 1) {
1375+
return true;
1376+
} else {
1377+
return warnings.get(0).contains("xpack.monitoring") == false;
13801378
}
1381-
return false;
13821379
}));
13831380
cleanupClient().performRequest(request);
13841381
}

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

Lines changed: 23 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,27 @@ 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+
AtomicBoolean searchTasksFound = new AtomicBoolean(false);
322+
selectTasksWithOpaqueId(responseMap, asyncSearchOpaqueId, task -> {
323+
if (task.get("action") instanceof String action && action.contains("indices:data/read/search")) {
324+
searchTasksFound.set(true);
325+
}
326+
});
327+
assertFalse("Expected no search tasks to be running", searchTasksFound.get());
328+
} catch (IOException e) {
329+
throw new RuntimeException(e);
330+
}
331+
});
311332
}
312333
}
313334

0 commit comments

Comments
 (0)