From 4d812e9fde9ba425ee8773614c2587faae7f3e61 Mon Sep 17 00:00:00 2001 From: kkewwei Date: Sat, 21 Sep 2024 13:30:01 +0800 Subject: [PATCH] Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClusterManagerNodes Signed-off-by: kkewwei --- .../SpecificClusterManagerNodesIT.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java index 713873bb222e2..34b29e1a79e11 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; @@ -255,19 +256,24 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { 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() - .admin() - .cluster() - .prepareState() - .execute() - .actionGet() - .getState() - .nodes() - .getClusterManagerNode() - .getName(), - equalTo(nextClusterManagerEligableNodeName) - ); + Supplier clusterManagerName = () -> { + try { + return internalCluster().nonClusterManagerClient() + .admin() + .cluster() + .prepareState() + .execute() + .actionGet() + .getState() + .nodes() + .getClusterManagerNode() + .getName(); + } catch (Exception e) { + logger.debug("failed to get cluster-manager name", e); + return null; + } + }; + assertThat(clusterManagerName.get(), equalTo(nextClusterManagerEligableNodeName)); assertThat( internalCluster().clusterManagerClient() .admin()