@@ -177,25 +177,57 @@ public void testCloneShallowSnapshotIndex() throws Exception {
177177 createIndex (remoteStoreEnabledIndexName , remoteStoreEnabledIndexSettings );
178178 indexRandomDocs (remoteStoreEnabledIndexName , randomIntBetween (5 , 10 ));
179179
180+ assertBusy (
181+ () -> client ().admin ()
182+ .cluster ()
183+ .prepareHealth ()
184+ .setWaitForStatus (org .opensearch .cluster .health .ClusterHealthStatus .YELLOW ) // don't require GREEN
185+ .setWaitForNoInitializingShards (true )
186+ .setWaitForNoRelocatingShards (true )
187+ .setTimeout (TimeValue .timeValueSeconds (60 ))
188+ .get ()
189+ );
190+
180191 final String snapshot = "snapshot" ;
181192 createFullSnapshot (snapshotRepoName , snapshot );
182- assert ( getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length == 0 );
193+ assertBusy (() -> assertEquals ( 0 , getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length ) );
183194
184195 indexRandomDocs (indexName , randomIntBetween (20 , 100 ));
185196
197+ assertBusy (
198+ () -> client ().admin ()
199+ .cluster ()
200+ .prepareHealth ()
201+ .setWaitForStatus (org .opensearch .cluster .health .ClusterHealthStatus .YELLOW )
202+ .setWaitForNoInitializingShards (true )
203+ .setWaitForNoRelocatingShards (true )
204+ .setTimeout (TimeValue .timeValueSeconds (60 ))
205+ .get ()
206+ );
207+
186208 final String shallowSnapshot = "shallow-snapshot" ;
187209 createFullSnapshot (shallowSnapshotRepoName , shallowSnapshot );
188- assert ( getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length == 1 );
210+ assertBusy (() -> assertEquals ( 1 , getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length ) );
189211
190212 if (randomBoolean ()) {
191213 assertAcked (admin ().indices ().prepareDelete (indexName ));
214+ assertBusy (
215+ () -> client ().admin ()
216+ .cluster ()
217+ .prepareHealth ()
218+ .setWaitForStatus (org .opensearch .cluster .health .ClusterHealthStatus .YELLOW )
219+ .setWaitForNoInitializingShards (true )
220+ .setWaitForNoRelocatingShards (true )
221+ .setTimeout (TimeValue .timeValueSeconds (60 ))
222+ .get ()
223+ );
192224 }
193225
194226 final String sourceSnapshot = shallowSnapshot ;
195227 final String targetSnapshot = "target-snapshot" ;
196228 assertAcked (startClone (shallowSnapshotRepoName , sourceSnapshot , targetSnapshot , indexName , remoteStoreEnabledIndexName ).get ());
197229 logger .info ("Lock files count: {}" , getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length );
198- assert ( getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length == 2 );
230+ assertBusy (() -> assertEquals ( 2 , getLockFilesInRemoteStore (remoteStoreEnabledIndexName , remoteStoreRepoName ).length ) );
199231 }
200232
201233 public void testShallowCloneNameAvailability () throws Exception {
0 commit comments