-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Test] Wait for clsuter to form before assertions #130973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
8018a91
5445ef6
ce1452c
c84e96a
c039174
5ded2bd
84945a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
| import org.elasticsearch.client.internal.Client; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.ProjectId; | ||
| import org.elasticsearch.cluster.metadata.RepositoryMetadata; | ||
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
|
|
@@ -96,24 +97,21 @@ public void testPreferFullMasterOverVotingOnlyNodes() throws Exception { | |
| internalCluster().setBootstrapMasterNodeIndex(0); | ||
| internalCluster().startNodes(2); | ||
| internalCluster().startNode(addRoles(Set.of(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE))); | ||
| internalCluster().startDataOnlyNodes(randomInt(2)); | ||
| assertBusy( | ||
| () -> assertThat( | ||
| clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().getLastCommittedConfiguration().getNodeIds().size(), | ||
| equalTo(3) | ||
| ) | ||
| final int numDataNodes = randomInt(2); | ||
| internalCluster().startDataOnlyNodes(numDataNodes); | ||
| internalCluster().validateClusterFormed(); | ||
|
|
||
| awaitClusterState( | ||
| state -> state.getLastCommittedConfiguration().getNodeIds().size() == 3 && state.nodes().size() == 3 + numDataNodes | ||
| ); | ||
| final String originalMaster = internalCluster().getMasterName(); | ||
|
|
||
| internalCluster().stopCurrentMasterNode(); | ||
| awaitMasterNode(); | ||
| internalCluster().validateClusterFormed(); | ||
| assertNotEquals(originalMaster, internalCluster().getMasterName()); | ||
| assertThat( | ||
| VotingOnlyNodePlugin.isVotingOnlyNode( | ||
| clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().nodes().getMasterNode() | ||
| ), | ||
| equalTo(false) | ||
| ); | ||
| final ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); | ||
| assertThat(state.nodes().size(), equalTo(2 + numDataNodes)); | ||
|
||
| assertThat(VotingOnlyNodePlugin.isVotingOnlyNode(state.nodes().getMasterNode()), equalTo(false)); | ||
| } | ||
|
|
||
| public void testBootstrapOnlyVotingOnlyNodes() throws Exception { | ||
|
|
@@ -157,21 +155,21 @@ public void testVotingOnlyNodesCannotBeMasterWithoutFullMasterNodes() throws Exc | |
| internalCluster().setBootstrapMasterNodeIndex(0); | ||
| internalCluster().startNode(); | ||
| internalCluster().startNodes(2, addRoles(Set.of(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE))); | ||
| internalCluster().startDataOnlyNodes(randomInt(2)); | ||
| assertBusy( | ||
| () -> assertThat( | ||
| clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().getLastCommittedConfiguration().getNodeIds().size(), | ||
| equalTo(3) | ||
| ) | ||
| final int numDataNodes = randomInt(2); | ||
| internalCluster().startDataOnlyNodes(numDataNodes); | ||
| internalCluster().validateClusterFormed(); | ||
|
|
||
| awaitClusterState( | ||
| state -> state.getLastCommittedConfiguration().getNodeIds().size() == 3 && state.nodes().size() == 3 + numDataNodes | ||
| ); | ||
| awaitMasterNode(); | ||
| final String oldMasterId = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().nodes().getMasterNodeId(); | ||
| final String oldMasterId = internalCluster().getMasterName(); | ||
|
|
||
| internalCluster().stopCurrentMasterNode(); | ||
| awaitMasterNotFound(); | ||
|
|
||
| // start a fresh full master node, which will be brought into the cluster as master by the voting-only nodes | ||
| final String newMaster = internalCluster().startNode(); | ||
| internalCluster().validateClusterFormed(); | ||
|
||
| assertEquals(newMaster, internalCluster().getMasterName()); | ||
| final String newMasterId = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().nodes().getMasterNodeId(); | ||
| assertNotEquals(oldMasterId, newMasterId); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather this remained as just an
awaitMasterNode(). That should be sufficient here...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is theoretically possible that the data node fails to join the new master so that
awaitMasterNode()returns without seeing the data node. If we later ask the data node (via a randomed client) about its master and it could fail with NPE. That said, it is not a practical concern for this test. So I reverted back to useawaitMasterNode.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that shouldn't be possible (i.e. I'd want the test to fail if that happens). The new master will start from the state that the old master last committed, which will include the data node, so the data node will automatically be part of the new master's cluster. The new master would only remove the data node from its cluster if something positively fails (e.g. network disconnect).