From 3ffc6200914a7747aaaaf31439c732ea4924982f Mon Sep 17 00:00:00 2001 From: kkewwei Date: Fri, 20 Sep 2024 22:07:04 +0800 Subject: [PATCH] Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClusterManagerNodes Signed-off-by: kkewwei --- .../SpecificClusterManagerNodesIT.java | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 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..393cc951248af 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java @@ -225,7 +225,7 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { equalTo(clusterManagerNodeName) ); assertThat( - internalCluster().nonClusterManagerClient() + internalCluster().clusterManagerClient() .admin() .cluster() .prepareState() @@ -237,6 +237,31 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { .getName(), equalTo(clusterManagerNodeName) ); + + 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 + + // make sure `nextClusterManagerEligableNodeName` has been elected as the new cluster-manager + waitUntil(() -> { + try { + return nextClusterManagerEligableNodeName.equals( + internalCluster().nonClusterManagerClient() + .admin() + .cluster() + .prepareState() + .execute() + .actionGet() + .getState() + .nodes() + .getClusterManagerNode() + .getName() + ); + } catch (Exception e) { + return false; + } + }); + assertThat( internalCluster().clusterManagerClient() .admin() @@ -248,40 +273,9 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { .nodes() .getClusterManagerNode() .getName(), - equalTo(clusterManagerNodeName) + equalTo(nextClusterManagerEligableNodeName) ); - 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() - .admin() - .cluster() - .prepareState() - .execute() - .actionGet() - .getState() - .nodes() - .getClusterManagerNode() - .getName(), - equalTo(nextClusterManagerEligableNodeName) - ); - assertThat( - internalCluster().clusterManagerClient() - .admin() - .cluster() - .prepareState() - .execute() - .actionGet() - .getState() - .nodes() - .getClusterManagerNode() - .getName(), - equalTo(nextClusterManagerEligableNodeName) - ); - }); internalCluster().stopRandomNode(InternalTestCluster.nameFilter(clusterManagerNodeName)); assertThat( internalCluster().nonClusterManagerClient()