From d2c4d603679068ee0e41b9d18608bce8fd20c4b6 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 Signed-off-by: kkewwei --- .../cluster/SpecificClusterManagerNodesIT.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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..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()