@@ -148,7 +148,7 @@ public void testCleanupRepository() throws IOException {
148
148
assertThat (response .result ().blobs (), equalTo (0L ));
149
149
}
150
150
151
- public void testCreateSnapshot () throws IOException {
151
+ public void testCreateSnapshot () throws Exception {
152
152
String repository = "test_repository" ;
153
153
assertTrue (createTestRepository (repository , FsRepository .TYPE , "{\" location\" : \" .\" }" ).isAcknowledged ());
154
154
@@ -165,12 +165,23 @@ public void testCreateSnapshot() throws IOException {
165
165
CreateSnapshotResponse response = createTestSnapshot (request );
166
166
assertEquals (waitForCompletion ? RestStatus .OK : RestStatus .ACCEPTED , response .status ());
167
167
if (waitForCompletion == false ) {
168
- // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
169
- AcknowledgedResponse deleteResponse = execute (
170
- new DeleteSnapshotRequest (repository , snapshot ),
171
- highLevelClient ().snapshot ()::delete , highLevelClient ().snapshot ()::deleteAsync
172
- );
173
- assertTrue (deleteResponse .isAcknowledged ());
168
+ // busy assert on the delete because a known race condition could cause the delete request to not see
169
+ // the snapshot if delete and snapshot finalization happen at the same time
170
+ // See https://github.com/elastic/elasticsearch/issues/53509#issuecomment-603899620 for details
171
+ // TODO: Remove busy assert in 7.x+ once this race is fixed
172
+ assertBusy (() -> {
173
+ // If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
174
+ AcknowledgedResponse deleteResponse ;
175
+ try {
176
+ deleteResponse = execute (
177
+ new DeleteSnapshotRequest (repository , snapshot ),
178
+ highLevelClient ().snapshot ()::delete , highLevelClient ().snapshot ()::deleteAsync
179
+ );
180
+ } catch (Exception e ) {
181
+ throw new AssertionError (e );
182
+ }
183
+ assertTrue (deleteResponse .isAcknowledged ());
184
+ });
174
185
}
175
186
}
176
187
0 commit comments