gnodet-bot commented on code in PR #29085:
URL: https://github.com/apache/camel/pull/29085#discussion_r4456343590
##########
components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/RaftNodesState.java:
##########
@@ -48,6 +58,36 @@ private static void setLevel(Protocol protocol, String
level) {
}
}
+ /**
+ * Wait until the election of every node of the JVM is over, that is until
no thread votes anymore.
+ * <p>
+ * A node that closes its channel while it still votes keeps voting
forever when it has a majority and no leader (a
+ * cluster of a single member): its voting thread is only told to stop. As
the log (and thus the term) of a node is
+ * shared by the nodes with the same Raft id in the JVM, the thread of a
former test keeps increasing the term of
+ * the node of the next tests, which then refuses the term of the leader
and never accepts it. Wait before closing
+ * the channels, so that the thread ends by itself.
+ * <p>
+ * This is best effort: when an election does not end, the threads still
voting are logged and the test goes on with
+ * its cleanup.
+ */
+ public static void awaitElectionsFinished() {
+ try {
+ await().atMost(5, TimeUnit.SECONDS)
+ .pollInterval(50, TimeUnit.MILLISECONDS)
+ .until(() -> votingThreads().isEmpty());
+ } catch (ConditionTimeoutException e) {
+ // the cleanup of the test goes on, and its result tells why
+ LOG.warn("The election does not end, these threads still vote:
{}", votingThreads());
Review Comment:
💡 **Minor observation:** `votingThreads()` is called twice when the timeout
is hit — once as the final poll condition inside `until()`, and again here in
`LOG.warn()`. Between those two calls, some threads may have finished, so the
logged list could show fewer (or zero) threads than what actually caused the
timeout. Since this is best-effort test cleanup code and the log is purely
diagnostic, the impact is negligible — but capturing the list once before the
`catch` block and reusing it would make the message more accurate:
```suggestion
} catch (ConditionTimeoutException e) {
// the cleanup of the test goes on, and its result tells why
List<String> stillVoting = votingThreads();
LOG.warn("The election does not end, these threads still vote:
{}", stillVoting);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]