diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java index 4616234f145..616850c513a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java @@ -144,6 +144,14 @@ public class SnapshotIT extends ESRestHighLevelClientTestCase { CreateSnapshotResponse response = createTestSnapshot(request); assertEquals(waitForCompletion ? RestStatus.OK : RestStatus.ACCEPTED, response.status()); + if (waitForCompletion == false) { + // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task + AcknowledgedResponse deleteResponse = execute( + new DeleteSnapshotRequest(repository, snapshot), + highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync + ); + assertTrue(deleteResponse.isAcknowledged()); + } } public void testGetSnapshots() throws IOException {