Skip to content

Commit ff820ed

Browse files
Fix flaky test SegmentReplicationStatsIT.testMultipleIndices (opensearch-project#12070) (opensearch-project#12100)
(cherry picked from commit 2f8d267) Signed-off-by: Poojita Raj <poojiraj@amazon.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 0330e08 commit ff820ed

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationStatsIT.java

+32-29
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ public void testMultipleIndices() throws Exception {
268268
internalCluster().startClusterManagerOnlyNode();
269269
final String index_2 = "tst-index-2";
270270
List<String> nodes = new ArrayList<>();
271-
final String primaryNode = internalCluster().startNode();
271+
final String primaryNode = internalCluster().startDataOnlyNode();
272272
nodes.add(primaryNode);
273273
createIndex(INDEX_NAME, index_2);
274274

275275
ensureYellowAndNoInitializingShards(INDEX_NAME, index_2);
276-
nodes.add(internalCluster().startNode());
276+
nodes.add(internalCluster().startDataOnlyNode());
277277
ensureGreen(INDEX_NAME, index_2);
278278

279279
final long numDocs = scaledRandomIntBetween(50, 100);
@@ -284,44 +284,47 @@ public void testMultipleIndices() throws Exception {
284284
refresh(INDEX_NAME, index_2);
285285
waitForSearchableDocs(INDEX_NAME, numDocs, nodes);
286286
waitForSearchableDocs(index_2, numDocs, nodes);
287+
ensureSearchable(INDEX_NAME, index_2);
287288

288289
final IndexShard index_1_primary = getIndexShard(primaryNode, INDEX_NAME);
289290
final IndexShard index_2_primary = getIndexShard(primaryNode, index_2);
290291

291292
assertTrue(index_1_primary.routingEntry().primary());
292293
assertTrue(index_2_primary.routingEntry().primary());
293294

294-
// test both indices are returned in the response.
295-
SegmentReplicationStatsResponse segmentReplicationStatsResponse = client().admin()
296-
.indices()
297-
.prepareSegmentReplicationStats()
298-
.execute()
299-
.actionGet();
295+
assertBusy(() -> {
296+
// test both indices are returned in the response.
297+
SegmentReplicationStatsResponse segmentReplicationStatsResponse = dataNodeClient().admin()
298+
.indices()
299+
.prepareSegmentReplicationStats()
300+
.execute()
301+
.actionGet();
300302

301-
Map<String, List<SegmentReplicationPerGroupStats>> replicationStats = segmentReplicationStatsResponse.getReplicationStats();
302-
assertEquals(2, replicationStats.size());
303-
List<SegmentReplicationPerGroupStats> replicationPerGroupStats = replicationStats.get(INDEX_NAME);
304-
assertEquals(1, replicationPerGroupStats.size());
305-
SegmentReplicationPerGroupStats perGroupStats = replicationPerGroupStats.get(0);
306-
assertEquals(perGroupStats.getShardId(), index_1_primary.shardId());
307-
Set<SegmentReplicationShardStats> replicaStats = perGroupStats.getReplicaStats();
308-
assertEquals(1, replicaStats.size());
309-
for (SegmentReplicationShardStats replica : replicaStats) {
310-
assertNotNull(replica.getCurrentReplicationState());
311-
}
303+
Map<String, List<SegmentReplicationPerGroupStats>> replicationStats = segmentReplicationStatsResponse.getReplicationStats();
304+
assertEquals(2, replicationStats.size());
305+
List<SegmentReplicationPerGroupStats> replicationPerGroupStats = replicationStats.get(INDEX_NAME);
306+
assertEquals(1, replicationPerGroupStats.size());
307+
SegmentReplicationPerGroupStats perGroupStats = replicationPerGroupStats.get(0);
308+
assertEquals(perGroupStats.getShardId(), index_1_primary.shardId());
309+
Set<SegmentReplicationShardStats> replicaStats = perGroupStats.getReplicaStats();
310+
assertEquals(1, replicaStats.size());
311+
for (SegmentReplicationShardStats replica : replicaStats) {
312+
assertNotNull(replica.getCurrentReplicationState());
313+
}
312314

313-
replicationPerGroupStats = replicationStats.get(index_2);
314-
assertEquals(1, replicationPerGroupStats.size());
315-
perGroupStats = replicationPerGroupStats.get(0);
316-
assertEquals(perGroupStats.getShardId(), index_2_primary.shardId());
317-
replicaStats = perGroupStats.getReplicaStats();
318-
assertEquals(1, replicaStats.size());
319-
for (SegmentReplicationShardStats replica : replicaStats) {
320-
assertNotNull(replica.getCurrentReplicationState());
321-
}
315+
replicationPerGroupStats = replicationStats.get(index_2);
316+
assertEquals(1, replicationPerGroupStats.size());
317+
perGroupStats = replicationPerGroupStats.get(0);
318+
assertEquals(perGroupStats.getShardId(), index_2_primary.shardId());
319+
replicaStats = perGroupStats.getReplicaStats();
320+
assertEquals(1, replicaStats.size());
321+
for (SegmentReplicationShardStats replica : replicaStats) {
322+
assertNotNull(replica.getCurrentReplicationState());
323+
}
324+
}, 30, TimeUnit.SECONDS);
322325

323326
// test only single index queried.
324-
segmentReplicationStatsResponse = client().admin()
327+
SegmentReplicationStatsResponse segmentReplicationStatsResponse = dataNodeClient().admin()
325328
.indices()
326329
.prepareSegmentReplicationStats()
327330
.setIndices(index_2)

0 commit comments

Comments
 (0)