@@ -131,7 +131,7 @@ public void testVerifyRepository() throws IOException {
131131 assertThat (response .getNodes ().size (), equalTo (1 ));
132132 }
133133
134- public void testCreateSnapshot () throws IOException {
134+ public void testCreateSnapshot () throws Exception {
135135 String repository = "test_repository" ;
136136 assertTrue (createTestRepository (repository , FsRepository .TYPE , "{\" location\" : \" .\" }" ).isAcknowledged ());
137137
@@ -145,12 +145,23 @@ public void testCreateSnapshot() throws IOException {
145145 CreateSnapshotResponse response = createTestSnapshot (request );
146146 assertEquals (waitForCompletion ? RestStatus .OK : RestStatus .ACCEPTED , response .status ());
147147 if (waitForCompletion == false ) {
148- // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
149- AcknowledgedResponse deleteResponse = execute (
150- new DeleteSnapshotRequest (repository , snapshot ),
151- highLevelClient ().snapshot ()::delete , highLevelClient ().snapshot ()::deleteAsync
152- );
153- assertTrue (deleteResponse .isAcknowledged ());
148+ // busy assert on the delete because a known race condition could cause the delete request to not see
149+ // the snapshot if delete and snapshot finalization happen at the same time
150+ // See https://github.com/elastic/elasticsearch/issues/53509#issuecomment-603899620 for details
151+ // TODO: Remove busy assert in 7.x+ once this race is fixed
152+ assertBusy (() -> {
153+ // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
154+ AcknowledgedResponse deleteResponse ;
155+ try {
156+ deleteResponse = execute (
157+ new DeleteSnapshotRequest (repository , snapshot ),
158+ highLevelClient ().snapshot ()::delete , highLevelClient ().snapshot ()::deleteAsync
159+ );
160+ } catch (Exception e ) {
161+ throw new AssertionError (e );
162+ }
163+ assertTrue (deleteResponse .isAcknowledged ());
164+ });
154165 }
155166 }
156167
0 commit comments