From 282812a00984bbeaefbfb71c9a72805d9f1787c9 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Tue, 8 Apr 2025 11:54:26 -0700 Subject: [PATCH] Fix ScaleIndexIT flaky test Signed-off-by: Prudhvi Godithi --- .../admin/indices/scale/searchonly/ScaleIndexIT.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexIT.java index 3e22084db96d8..06c6c6074fc47 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexIT.java @@ -148,11 +148,7 @@ public void testFullSearchOnlyReplicasFullLifecycle() throws Exception { // Test cluster health when one search replica is down internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodesWithSearchOnlyReplicas()[0])); - assertEquals( - "Index health should be YELLOW with one search replica down", - "YELLOW", - client().admin().cluster().prepareHealth(TEST_INDEX).get().getStatus().name() - ); + ensureYellow(TEST_INDEX); // Start a replacement search node and wait for recovery internalCluster().startSearchOnlyNode(); @@ -332,14 +328,12 @@ private String[] findNodesWithSearchOnlyReplicas() { ClusterState state = client().admin().cluster().prepareState().get().getState(); IndexRoutingTable indexRoutingTable = state.routingTable().index(TEST_INDEX); - // Use a set to avoid duplicates if multiple shards are on the same node Set nodeNames = new HashSet<>(); for (IndexShardRoutingTable shardTable : indexRoutingTable) { for (ShardRouting searchReplica : shardTable.searchOnlyReplicas()) { if (searchReplica.active()) { - String nodeId = searchReplica.currentNodeId(); - nodeNames.add(state.nodes().get(nodeId).getName()); + nodeNames.add(state.nodes().get(searchReplica.currentNodeId()).getName()); } } }