Skip to content

Commit 11fe8cd

Browse files
authored
[Tests] Fix flakiness by ensuring stable cluster (#39300) (#39356)
In integration tests where `setBootstrapMasterNodeIndex()` is used in combination with `autoMinMasterNodes = false` the cluster can start bootstrapping once the number of nodes set with the `setBootstrapMasterNodeIndex` have been started but it's not ensured that all nodes have successfully joined to form the cluster. This behaviour was introduced with 5db7ed2 and in order to ensure that the cluster is properly formed before proceeding with the integration test, use `ensureStableCluster()` with the appropriate number of expected nodes. Fixes: #39220
1 parent b6734b4 commit 11fe8cd

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public Settings onNodeStopped(String nodeName) throws IOException {
118118
public void testClearVotingTombstonesNotWaitingForRemoval() throws Exception {
119119
internalCluster().setBootstrapMasterNodeIndex(2);
120120
List<String> nodes = internalCluster().startNodes(3);
121+
ensureStableCluster(3);
121122
RestClient restClient = getRestClient();
122123
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodes.get(2)));
123124
assertThat(response.getStatusLine().getStatusCode(), is(200));
@@ -131,6 +132,7 @@ public void testClearVotingTombstonesNotWaitingForRemoval() throws Exception {
131132
public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
132133
internalCluster().setBootstrapMasterNodeIndex(2);
133134
List<String> nodes = internalCluster().startNodes(3);
135+
ensureStableCluster(3);
134136
RestClient restClient = getRestClient();
135137
String nodeToWithdraw = nodes.get(randomIntBetween(0, 2));
136138
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodeToWithdraw));
@@ -145,6 +147,7 @@ public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
145147
public void testFailsOnUnknownNode() throws Exception {
146148
internalCluster().setBootstrapMasterNodeIndex(2);
147149
internalCluster().startNodes(3);
150+
ensureStableCluster(3);
148151
RestClient restClient = getRestClient();
149152
try {
150153
restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/invalid"));

server/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void testCannotCommitStateThreeNodes() throws Exception {
284284
.build();
285285

286286
internalCluster().startNodes(3, settings);
287-
ensureGreen(); // ensure cluster state is recovered before we disrupt things
287+
ensureStableCluster(3);
288288

289289
final String master = internalCluster().getMasterName();
290290
Set<String> otherNodes = new HashSet<>(Arrays.asList(internalCluster().getNodeNames()));

server/src/test/java/org/elasticsearch/cluster/coordination/ElasticsearchNodeCommandIT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public void testDetachAbortedByUser() throws IOException {
250250
expectThrows(() -> detachCluster(environment, 0, true), ElasticsearchNodeCommand.ABORTED_BY_USER_MSG);
251251
}
252252

253-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39220")
254253
public void test3MasterNodes2Failed() throws Exception {
255254
internalCluster().setBootstrapMasterNodeIndex(2);
256255
List<String> masterNodes = new ArrayList<>();
@@ -268,8 +267,12 @@ public void test3MasterNodes2Failed() throws Exception {
268267
logger.info("--> start 2nd and 3rd master-eligible nodes and bootstrap");
269268
masterNodes.addAll(internalCluster().startMasterOnlyNodes(2)); // node ordinals 2 and 3
270269

270+
logger.info("--> wait for all nodes to join the cluster");
271+
ensureStableCluster(4);
272+
271273
logger.info("--> create index test");
272274
createIndex("test");
275+
ensureGreen("test");
273276

274277
logger.info("--> stop 2nd and 3d master eligible node");
275278
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));

0 commit comments

Comments
 (0)