Skip to content

Commit b73b853

Browse files
author
Sandeep Kumawat
committed
Fix flaky test SegmentReplicationIT.testReplicaAlreadyAtCheckpoint
Signed-off-by: Sandeep Kumawat <skumwt@amazon.com> Signed-off-by: skumwt <skumwt@amazon.com>
1 parent 05b40f0 commit b73b853

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,28 +1892,35 @@ 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-
18961895
waitForSearchableDocs(1, primaryNode, replicaNode, replicaNode2);
18971896

18981897
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNode));
18991898
ensureYellowAndNoInitializingShards(INDEX_NAME);
1900-
IndexShard replica_1 = getIndexShard(replicaNode, INDEX_NAME);
1901-
IndexShard replica_2 = getIndexShard(replicaNode2, INDEX_NAME);
1899+
AtomicReference<IndexShard> replica_1 = new AtomicReference<>();
1900+
AtomicReference<IndexShard> replica_2 = new AtomicReference<>();
19021901
// wait until a replica is promoted & finishes engine flip, we don't care which one
19031902
AtomicReference<IndexShard> primary = new AtomicReference<>();
19041903
assertBusy(() -> {
1905-
assertTrue("replica should be promoted as a primary", replica_1.routingEntry().primary() || replica_2.routingEntry().primary());
1906-
primary.set(replica_1.routingEntry().primary() ? replica_1 : replica_2);
1907-
});
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("replica should be promoted as a primary", replica_1.get().routingEntry().primary() || replica_2.get().routingEntry().primary());
1913+
primary.set(replica_1.get().routingEntry().primary() ? replica_1.get() : replica_2.get());
1914+
}, 60, TimeUnit.SECONDS);
19081915

19091916
FlushRequest request = new FlushRequest(INDEX_NAME);
19101917
request.force(true);
19111918
primary.get().flush(request);
19121919

19131920
assertBusy(() -> {
19141921
assertEquals(
1915-
replica_1.getLatestReplicationCheckpoint().getSegmentInfosVersion(),
1916-
replica_2.getLatestReplicationCheckpoint().getSegmentInfosVersion()
1922+
replica_1.get().getLatestReplicationCheckpoint().getSegmentInfosVersion(),
1923+
replica_2.get().getLatestReplicationCheckpoint().getSegmentInfosVersion()
19171924
);
19181925
});
19191926

0 commit comments

Comments
 (0)