diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java index 713873bb222e2..20c5088071766 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java @@ -44,6 +44,7 @@ import org.opensearch.test.OpenSearchIntegTestCase.Scope; import java.io.IOException; +import java.util.function.Supplier; import static org.opensearch.test.NodeRoles.clusterManagerNode; import static org.opensearch.test.NodeRoles.dataOnlyNode; @@ -254,9 +255,9 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { logger.info("--> closing cluster-manager node (1)"); client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(clusterManagerNodeName)).get(); // removing the cluster-manager from the voting configuration immediately triggers the cluster-manager to step down - assertBusy(() -> { - assertThat( - internalCluster().nonClusterManagerClient() + Supplier getClusterManagerIfElected = () -> { + try { + return internalCluster().nonClusterManagerClient() .admin() .cluster() .prepareState() @@ -265,9 +266,14 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { .getState() .nodes() .getClusterManagerNode() - .getName(), - equalTo(nextClusterManagerEligableNodeName) - ); + .getName(); + } catch (Exception e) { + logger.debug("failed to get cluster-manager name", e); + return null; + } + }; + assertBusy(() -> { + assertThat(getClusterManagerIfElected.get(), equalTo(nextClusterManagerEligableNodeName)); assertThat( internalCluster().clusterManagerClient() .admin()