Skip to content

Commit 035709b

Browse files
author
Ali Beyad
committed
Wait for cluster to become quiescent between REST tests (#24148)
[TEST] ensures REST tests wait for cluster state updates to finish processing before moving to the next test
1 parent ee8aa89 commit 035709b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public void initClient() throws IOException {
125125
@After
126126
public final void cleanUpCluster() throws Exception {
127127
wipeCluster();
128+
waitForClusterStateUpdatesToFinish();
128129
logIfThereAreRunningTasks();
129130
}
130131

@@ -253,6 +254,22 @@ private void logIfThereAreRunningTasks() throws InterruptedException, IOExceptio
253254
*/
254255
}
255256

257+
/**
258+
* Waits for the cluster state updates to have been processed, so that no cluster
259+
* state updates are still in-progress when the next test starts.
260+
*/
261+
private void waitForClusterStateUpdatesToFinish() throws Exception {
262+
assertBusy(() -> {
263+
try {
264+
Response response = adminClient().performRequest("GET", "_cluster/pending_tasks");
265+
List<Object> tasks = (List<Object>) entityAsMap(response).get("tasks");
266+
assertTrue(tasks.isEmpty());
267+
} catch (IOException e) {
268+
fail("cannot get cluster's pending tasks: " + e.getMessage());
269+
}
270+
});
271+
}
272+
256273
/**
257274
* Used to obtain settings for the REST client that is used to send REST requests.
258275
*/

0 commit comments

Comments
 (0)