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