@@ -131,7 +131,7 @@ public void testVerifyRepository() throws IOException {
131
131
assertThat (response .getNodes ().size (), equalTo (1 ));
132
132
}
133
133
134
- public void testCreateSnapshot () throws IOException {
134
+ public void testCreateSnapshot () throws Exception {
135
135
String repository = "test_repository" ;
136
136
assertTrue (createTestRepository (repository , FsRepository .TYPE , "{\" location\" : \" .\" }" ).isAcknowledged ());
137
137
@@ -145,12 +145,23 @@ public void testCreateSnapshot() throws IOException {
145
145
CreateSnapshotResponse response = createTestSnapshot (request );
146
146
assertEquals (waitForCompletion ? RestStatus .OK : RestStatus .ACCEPTED , response .status ());
147
147
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
+ });
154
165
}
155
166
}
156
167
0 commit comments