Skip to content

Commit

Permalink
Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClus…
Browse files Browse the repository at this point in the history
…terManagerNodes

Signed-off-by: kkewwei <[email protected]>
  • Loading branch information
kkewwei committed Sep 21, 2024
1 parent 9537d39 commit 3ffc620
Showing 1 changed file with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
equalTo(clusterManagerNodeName)
);
assertThat(
internalCluster().nonClusterManagerClient()
internalCluster().clusterManagerClient()
.admin()
.cluster()
.prepareState()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 3ffc620

Please sign in to comment.