Skip to content

Commit ff2591d

Browse files
authored
Make NodeConnectionsService#connectToNodes deterministic (#94949)
Today the `CoordinatorTests` test suite is not totally deterministic because its behaviour depends on the iteration order of the JDK's unordered collections which are not under the control of our test seed. This commit makes `NodeConnectionsService#connectToNodes` iterate through the nodes using `DiscoveryNodes#mastersFirstStream`, which is made deterministic by #94948. It's an ugly hack to do some extra work in production just for the sake of tests, but we're only sorting at most a few hundred elements here so it's not a huge deal. Relates #94946
1 parent 964e309 commit ff2591d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

server/src/main/java/org/elasticsearch/cluster/NodeConnectionsService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.ArrayList;
3131
import java.util.HashMap;
3232
import java.util.HashSet;
33+
import java.util.Iterator;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Set;
@@ -99,7 +100,9 @@ public void connectToNodes(DiscoveryNodes discoveryNodes, Runnable onCompletion)
99100
final List<Runnable> runnables = new ArrayList<>(discoveryNodes.getSize());
100101
try (var refs = new RefCountingRunnable(onCompletion)) {
101102
synchronized (mutex) {
102-
for (final DiscoveryNode discoveryNode : discoveryNodes) {
103+
// Ugly hack: when https://github.com/elastic/elasticsearch/issues/94946 is fixed, just iterate over discoveryNodes here
104+
for (final Iterator<DiscoveryNode> iterator = discoveryNodes.mastersFirstStream().iterator(); iterator.hasNext();) {
105+
final DiscoveryNode discoveryNode = iterator.next();
103106
ConnectionTarget connectionTarget = targetsByNode.get(discoveryNode);
104107
final boolean isNewNode = connectionTarget == null;
105108
if (isNewNode) {

0 commit comments

Comments
 (0)