From 8892408edd8088cdde8f21ecbf21d1cfcf72efb3 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 20 Nov 2018 14:09:15 +0100 Subject: [PATCH] SNAPSHOT: Fix Leaking Snapshot Task in IT (#35657) * SNAPSHOT: Fix Leaking Snapshot Task in IT * If the test randomization causes the request to not wait for snapshot completion then the deleting of the still in progress snapshot could fail in the after hook * Fixed by deleting the snapshot in the test * Closes #35642 --- .../test/java/org/elasticsearch/client/SnapshotIT.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 {