Skip to content

Commit 17b441e

Browse files
authored
[7.x] Fix testDeleteActionDeletesSearchableSnapshot (#68751) (#68899)
It could happen for ILM to run so fast the test did not get to pick up the snapshot name from the ILM execution state. This changes the implementation of the test to not rely on that snapshot name, but to assert that the test repository is empty after ILM completes the cycle for the first generation backing index. (cherry picked from commit 0c1d799) Signed-off-by: Andrei Dan <[email protected]>
1 parent c786af9 commit 17b441e

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.apache.http.entity.ContentType;
1111
import org.apache.http.entity.StringEntity;
12-
import org.apache.http.util.EntityUtils;
1312
import org.elasticsearch.client.Request;
1413
import org.elasticsearch.client.Response;
1514
import org.elasticsearch.cluster.metadata.DataStream;
@@ -153,8 +152,8 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio
153152
TimeUnit.SECONDS);
154153
}
155154

156-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/54433")
157-
public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
155+
@SuppressWarnings("unchecked")
156+
public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
158157
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
159158

160159
// create policy with cold and delete phases
@@ -182,32 +181,28 @@ public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
182181
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
183182
rolloverMaxOneDocCondition(client(), dataStream);
184183

185-
String[] snapshotName = new String[1];
186184
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1L);
187185
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
188-
assertTrue(waitUntil(() -> {
189-
try {
190-
Map<String, Object> explainIndex = explainIndex(client(), backingIndexName);
191-
if (explainIndex == null) {
192-
// in case we missed the original index and it was deleted
193-
explainIndex = explainIndex(client(), restoredIndexName);
194-
}
195-
snapshotName[0] = (String) explainIndex.get("snapshot_name");
196-
return snapshotName[0] != null;
197-
} catch (IOException e) {
198-
return false;
199-
}
200-
}, 30, TimeUnit.SECONDS));
201-
assertBusy(() -> assertFalse(indexExists(restoredIndexName)));
186+
187+
// let's wait for ILM to finish
188+
assertBusy(() -> assertFalse(indexExists(backingIndexName)), 60, TimeUnit.SECONDS);
189+
assertBusy(() -> assertFalse(indexExists(restoredIndexName)), 60, TimeUnit.SECONDS);
202190

203191
assertTrue("the snapshot we generate in the cold phase should be deleted by the delete phase", waitUntil(() -> {
204-
try {
205-
Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/" + snapshotName[0]);
206-
Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest);
207-
return EntityUtils.toString(getSnapshotsResponse.getEntity()).contains("snapshot_missing_exception");
208-
} catch (IOException e) {
209-
return false;
210-
}
192+
try {
193+
Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/_all");
194+
Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest);
195+
196+
Map<String, Object> responseMap;
197+
try (InputStream is = getSnapshotsResponse.getEntity().getContent()) {
198+
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
199+
}
200+
List<Map<String, Object>> snapshots = (List<Map<String, Object>>) responseMap.get("snapshots");
201+
return snapshots.size() == 0;
202+
} catch (Exception e) {
203+
logger.error(e.getMessage(), e);
204+
return false;
205+
}
211206
}, 30, TimeUnit.SECONDS));
212207
}
213208

0 commit comments

Comments
 (0)