Skip to content

Commit af5a3d1

Browse files
Add assertBusy to failing snapshot tests (opensearch-project#16146) (opensearch-project#16147)
(cherry picked from commit 43e7597) Signed-off-by: Lakshya Taragi <lakshya.taragi@gmail.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3f71934 commit af5a3d1

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

+25-15
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void testStatusApiConsistency() {
116116
assertEquals(snapshotStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime());
117117
}
118118

119-
public void testStatusAPICallForShallowCopySnapshot() {
119+
public void testStatusAPICallForShallowCopySnapshot() throws Exception {
120120
disableRepoConsistencyCheck("Remote store repository is being used for the test");
121121
internalCluster().startClusterManagerOnlyNode();
122122
internalCluster().startDataOnlyNode();
@@ -136,15 +136,24 @@ public void testStatusAPICallForShallowCopySnapshot() {
136136
final String snapshot = "snapshot";
137137
createFullSnapshot(snapshotRepoName, snapshot);
138138

139-
final SnapshotStatus snapshotStatus = getSnapshotStatus(snapshotRepoName, snapshot);
140-
assertThat(snapshotStatus.getState(), is(SnapshotsInProgress.State.SUCCESS));
139+
assertBusy(() -> {
140+
final SnapshotStatus snapshotStatus = client().admin()
141+
.cluster()
142+
.prepareSnapshotStatus(snapshotRepoName)
143+
.setSnapshots(snapshot)
144+
.execute()
145+
.actionGet()
146+
.getSnapshots()
147+
.get(0);
148+
assertThat(snapshotStatus.getState(), is(SnapshotsInProgress.State.SUCCESS));
141149

142-
final SnapshotIndexShardStatus snapshotShardState = stateFirstShard(snapshotStatus, indexName);
143-
assertThat(snapshotShardState.getStage(), is(SnapshotIndexShardStage.DONE));
144-
assertThat(snapshotShardState.getStats().getTotalFileCount(), greaterThan(0));
145-
assertThat(snapshotShardState.getStats().getTotalSize(), greaterThan(0L));
146-
assertThat(snapshotShardState.getStats().getIncrementalFileCount(), greaterThan(0));
147-
assertThat(snapshotShardState.getStats().getIncrementalSize(), greaterThan(0L));
150+
final SnapshotIndexShardStatus snapshotShardState = stateFirstShard(snapshotStatus, indexName);
151+
assertThat(snapshotShardState.getStage(), is(SnapshotIndexShardStage.DONE));
152+
assertThat(snapshotShardState.getStats().getTotalFileCount(), greaterThan(0));
153+
assertThat(snapshotShardState.getStats().getTotalSize(), greaterThan(0L));
154+
assertThat(snapshotShardState.getStats().getIncrementalFileCount(), greaterThan(0));
155+
assertThat(snapshotShardState.getStats().getIncrementalSize(), greaterThan(0L));
156+
}, 20, TimeUnit.SECONDS);
148157
}
149158

150159
public void testStatusAPICallInProgressSnapshot() throws Exception {
@@ -193,7 +202,7 @@ public void testExceptionOnMissingSnapBlob() throws IOException {
193202
);
194203
}
195204

196-
public void testExceptionOnMissingShardLevelSnapBlob() throws IOException {
205+
public void testExceptionOnMissingShardLevelSnapBlob() throws Exception {
197206
disableRepoConsistencyCheck("This test intentionally corrupts the repository");
198207

199208
final Path repoPath = randomRepoPath();
@@ -216,11 +225,12 @@ public void testExceptionOnMissingShardLevelSnapBlob() throws IOException {
216225
repoPath.resolve(resolvePath(indexId, "0"))
217226
.resolve(BlobStoreRepository.SNAPSHOT_PREFIX + snapshotInfo.snapshotId().getUUID() + ".dat")
218227
);
219-
220-
expectThrows(
221-
SnapshotMissingException.class,
222-
() -> client().admin().cluster().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").execute().actionGet()
223-
);
228+
assertBusy(() -> {
229+
expectThrows(
230+
SnapshotMissingException.class,
231+
() -> client().admin().cluster().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").execute().actionGet()
232+
);
233+
}, 20, TimeUnit.SECONDS);
224234
}
225235

226236
public void testGetSnapshotsWithoutIndices() throws Exception {

0 commit comments

Comments
 (0)