Skip to content

Commit 8018a91

Browse files
committed
[Test] Wait for stable cluster before assertion
Nodes that are not publish quorum may not have applied the latest update when awaitMasterNode returns. This PR fixes it by waiting for the desired number of nodes. Relates: elastic#129118 Resolves: elastic#130883
1 parent 05b55b0 commit 8018a91

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,6 @@ tests:
564564
- class: org.elasticsearch.cluster.ClusterStateSerializationTests
565565
method: testSerializationPreMultiProject
566566
issue: https://github.com/elastic/elasticsearch/issues/130872
567-
- class: org.elasticsearch.cluster.coordination.votingonly.VotingOnlyNodePluginTests
568-
method: testPreferFullMasterOverVotingOnlyNodes
569-
issue: https://github.com/elastic/elasticsearch/issues/130883
570567

571568
# Examples:
572569
#

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,13 @@ public void awaitMasterNode(String viaNode, String masterNodeName) {
965965
}
966966

967967
/**
968-
* Waits for all nodes in the cluster to have a consistent view of which node is currently the master.
968+
* Waits for all nodes forming the publish quorum in the cluster to have a consistent view of which node is currently the master.
969969
*/
970970
public void awaitMasterNode() {
971971
// The cluster health API always runs on the master node, and the master only completes cluster state publication when all nodes
972-
// in the cluster have accepted the new cluster state. By waiting for all events to have finished on the master node, we ensure
973-
// that the whole cluster has a consistent view of which node is the master.
972+
// forming the publish quorum have accepted the new cluster state. By waiting for all events to have finished on the
973+
// master node, we ensure that all nodes that are part of the publish quorum have a consistent view of which node is the master.
974+
// But nodes that are _not_ part of the quorum might still not have the same view yet.
974975
clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT).setTimeout(TEST_REQUEST_TIMEOUT).setWaitForEvents(Priority.LANGUID).get();
975976
}
976977

x-pack/plugin/voting-only-node/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/votingonly/VotingOnlyNodePluginTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public void testPreferFullMasterOverVotingOnlyNodes() throws Exception {
9696
internalCluster().setBootstrapMasterNodeIndex(0);
9797
internalCluster().startNodes(2);
9898
internalCluster().startNode(addRoles(Set.of(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE)));
99-
internalCluster().startDataOnlyNodes(randomInt(2));
99+
final int numDataNodes = randomInt(2);
100+
internalCluster().startDataOnlyNodes(numDataNodes);
100101
assertBusy(
101102
() -> assertThat(
102103
clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().getLastCommittedConfiguration().getNodeIds().size(),
@@ -108,6 +109,7 @@ public void testPreferFullMasterOverVotingOnlyNodes() throws Exception {
108109
internalCluster().stopCurrentMasterNode();
109110
awaitMasterNode();
110111
assertNotEquals(originalMaster, internalCluster().getMasterName());
112+
ensureStableCluster(2 + numDataNodes); // wait for all nodes to join
111113
assertThat(
112114
VotingOnlyNodePlugin.isVotingOnlyNode(
113115
clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().nodes().getMasterNode()

0 commit comments

Comments
 (0)