Skip to content

Commit 8c2e3d0

Browse files
authored
[test] Improve failure mode of NodeConnectionsServiceTests (#110956) (#115489)
Currently, when NodeConnectionServiceTests #testOnlyBlocksOnConnectionsToNewNodes fails due to an exception, it resets a CyclicBarrier which causes an AssertionError to be thrown on a connector thread. The AssertionError ends up being uncaught, so when we try to stop the TransportService in the tear-down it blocks indefinitely waiting for that connector thread to complete. This causes the original exception to be obscured. This change makes the connector thread fail more gracefully so that the test can complete and the root cause will be revealed. (cherry picked from commit 61bf77e) Closes #115381
1 parent daaf304 commit 8c2e3d0

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -615,29 +615,25 @@ public TransportAddress[] addressesFromString(String address) {
615615
return new TransportAddress[0];
616616
}
617617

618-
private void runConnectionBlock(CheckedRunnable<Exception> connectionBlock) {
618+
private void runConnectionBlock(CheckedRunnable<Exception> connectionBlock) throws Exception {
619619
if (connectionBlock == null) {
620620
return;
621621
}
622-
try {
623-
connectionBlock.run();
624-
} catch (Exception e) {
625-
throw new AssertionError(e);
626-
}
622+
connectionBlock.run();
627623
}
628624

629625
@Override
630626
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Connection> listener) {
631627
final CheckedRunnable<Exception> connectionBlock = nodeConnectionBlocks.get(node);
632628
if (profile == null && randomConnectionExceptions && randomBoolean()) {
633-
threadPool.generic().execute(() -> {
629+
threadPool.generic().execute(() -> ActionListener.completeWith(listener, () -> {
634630
runConnectionBlock(connectionBlock);
635-
listener.onFailure(new ConnectTransportException(node, "simulated"));
636-
});
631+
throw new ConnectTransportException(node, "simulated");
632+
}));
637633
} else {
638-
threadPool.generic().execute(() -> {
634+
threadPool.generic().execute(() -> ActionListener.completeWith(listener, () -> {
639635
runConnectionBlock(connectionBlock);
640-
listener.onResponse(new Connection() {
636+
return new Connection() {
641637
private final ListenableActionFuture<Void> closeListener = new ListenableActionFuture<>();
642638
private final ListenableActionFuture<Void> removedListener = new ListenableActionFuture<>();
643639

@@ -696,8 +692,8 @@ public boolean decRef() {
696692
public boolean hasReferences() {
697693
return refCounted.hasReferences();
698694
}
699-
});
700-
});
695+
};
696+
}));
701697
}
702698
}
703699

0 commit comments

Comments
 (0)