Skip to content

Commit 26a230c

Browse files
skumawat2025skumwt
authored and
Harsh Kothari
committed
Fix flaky test SegmentReplicationIT.testReplicaAlreadyAtCheckpoint (opensearch-project#17216)
* Fix flaky test SegmentReplicationIT.testReplicaAlreadyAtCheckpoint Signed-off-by: skumwt <skumwt@amazon.com> * Fix flaky test SegmentReplicationIT.testReplicaAlreadyAtCheckpoint Signed-off-by: Sandeep Kumawat <skumwt@amazon.com> Signed-off-by: skumwt <skumwt@amazon.com> --------- Signed-off-by: skumwt <skumwt@amazon.com> Signed-off-by: Sandeep Kumawat <skumwt@amazon.com> Co-authored-by: skumwt <skumwt@amazon.com> Signed-off-by: Harsh Kothari <techarsh@amazon.com>
1 parent 265aa09 commit 26a230c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,26 +1892,38 @@ public void testReplicaAlreadyAtCheckpoint() throws Exception {
18921892
// index a doc.
18931893
client().prepareIndex(INDEX_NAME).setId("1").setSource("foo", randomInt()).get();
18941894
refresh(INDEX_NAME);
1895+
waitForSearchableDocs(1, primaryNode, replicaNode, replicaNode2);
18951896

18961897
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNode));
18971898
ensureYellowAndNoInitializingShards(INDEX_NAME);
1898-
IndexShard replica_1 = getIndexShard(replicaNode, INDEX_NAME);
1899-
IndexShard replica_2 = getIndexShard(replicaNode2, INDEX_NAME);
1899+
AtomicReference<IndexShard> replica_1 = new AtomicReference<>();
1900+
AtomicReference<IndexShard> replica_2 = new AtomicReference<>();
19001901
// wait until a replica is promoted & finishes engine flip, we don't care which one
19011902
AtomicReference<IndexShard> primary = new AtomicReference<>();
19021903
assertBusy(() -> {
1903-
assertTrue("replica should be promoted as a primary", replica_1.routingEntry().primary() || replica_2.routingEntry().primary());
1904-
primary.set(replica_1.routingEntry().primary() ? replica_1 : replica_2);
1905-
});
1904+
IndexShard replicaShard1 = getIndexShard(replicaNode, INDEX_NAME);
1905+
IndexShard replicaShard2 = getIndexShard(replicaNode2, INDEX_NAME);
1906+
1907+
assertNotNull("Replica shard 1 should not be null", replicaShard1);
1908+
assertNotNull("Replica shard 2 should not be null", replicaShard2);
1909+
1910+
replica_1.set(replicaShard1);
1911+
replica_2.set(replicaShard2);
1912+
assertTrue(
1913+
"replica should be promoted as a primary",
1914+
replica_1.get().routingEntry().primary() || replica_2.get().routingEntry().primary()
1915+
);
1916+
primary.set(replica_1.get().routingEntry().primary() ? replica_1.get() : replica_2.get());
1917+
}, 60, TimeUnit.SECONDS);
19061918

19071919
FlushRequest request = new FlushRequest(INDEX_NAME);
19081920
request.force(true);
19091921
primary.get().flush(request);
19101922

19111923
assertBusy(() -> {
19121924
assertEquals(
1913-
replica_1.getLatestReplicationCheckpoint().getSegmentInfosVersion(),
1914-
replica_2.getLatestReplicationCheckpoint().getSegmentInfosVersion()
1925+
replica_1.get().getLatestReplicationCheckpoint().getSegmentInfosVersion(),
1926+
replica_2.get().getLatestReplicationCheckpoint().getSegmentInfosVersion()
19151927
);
19161928
});
19171929

0 commit comments

Comments
 (0)