Skip to content

Commit 277ccba

Browse files
authored
[Zen2] fix NodeJoinTests#testConcurrentJoining() (#36033)
Today we sometimes create a setup in which the node is a quorum on its own, which allows it to win a pre-voting round and schedule an election essentially at will, causing it to discard all the joins it just received and fail the test. This change excludes this case, preventing stray elections from ruining things.
1 parent 87408b0 commit 277ccba

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
import static java.util.Collections.emptyList;
7272
import static java.util.Collections.emptyMap;
73+
import static java.util.Collections.singletonList;
7374
import static org.elasticsearch.transport.TransportService.HANDSHAKE_ACTION_NAME;
7475
import static org.hamcrest.Matchers.containsString;
7576

@@ -418,12 +419,12 @@ public void testConcurrentJoining() {
418419
List<DiscoveryNode> nodes = IntStream.rangeClosed(1, randomIntBetween(2, 5))
419420
.mapToObj(nodeId -> newNode(nodeId, true)).collect(Collectors.toList());
420421

421-
VotingConfiguration votingConfiguration = new VotingConfiguration(
422-
randomSubsetOf(randomIntBetween(1, nodes.size()), nodes).stream().map(DiscoveryNode::getId).collect(Collectors.toSet()));
422+
DiscoveryNode localNode = nodes.get(0);
423+
VotingConfiguration votingConfiguration = new VotingConfiguration(randomValueOtherThan(singletonList(localNode),
424+
() -> randomSubsetOf(randomIntBetween(1, nodes.size()), nodes)).stream().map(DiscoveryNode::getId).collect(Collectors.toSet()));
423425

424426
logger.info("Voting configuration: {}", votingConfiguration);
425427

426-
DiscoveryNode localNode = nodes.get(0);
427428
long initialTerm = randomLongBetween(1, 10);
428429
long initialVersion = randomLongBetween(1, 10);
429430
setupRealMasterServiceAndCoordinator(initialTerm, initialState(false, localNode, initialTerm, initialVersion, votingConfiguration));
@@ -488,12 +489,7 @@ public void testConcurrentJoining() {
488489
} catch (InterruptedException | BrokenBarrierException e) {
489490
throw new RuntimeException(e);
490491
}
491-
try {
492-
joinNode(joinRequest);
493-
} catch (CoordinationStateRejectedException ignore) {
494-
// ignore: even the "correct" requests may fail as a duplicate because a concurrent election may cause a node to
495-
// spontaneously join.
496-
}
492+
joinNode(joinRequest);
497493
}, "process " + joinRequest)).collect(Collectors.toList());
498494

499495
assertionThread.start();

0 commit comments

Comments
 (0)