Skip to content

[Bug] ConnectionMonitorLogTest.connectAndDisconnectProduceMatchingLogEntries is flaky #124

Open

Description

@codegeek

Problem

ConnectionMonitorLogTest.connectAndDisconnectProduceMatchingLogEntries (jircd-integration-tests/src/test/java/net/jircd/integration/ConnectionMonitorLogTest.java:44) failed once in a full ./gradlew build on 2026-10-27, on the #121 branch (which changed no connection or logging code):

ConnectionMonitorLogTest > connectAndDisconnectProduceMatchingLogEntries() FAILED
> Task :jircd-integration-tests:test FAILED

It passed when run alone right afterwards, and in two later full builds of the same tree (one with cleanTest). The assertion message wasn't kept, so we don't know which check failed.

Suspected cause (unverified)

The test attaches a LogCapture to the static ConnectionMonitorLog logger, then takes the first captured connection-event=connected line and the first connection-event=disconnected line, and asserts their connection tokens are equal. The capture isn't scoped to this test's server or connection. A connection from an earlier test that is still closing asynchronously could log its disconnected line into the capture first. The tokens would then differ, and the assertion at line 65 would fail. A slow machine hitting the 5 s awaitMessage timeout is another possibility.

Suggested fix

  • Await the disconnected line whose token matches this test's connected token, rather than the first disconnected line.
  • Optionally, also filter the connected line by this client's local port (remoteAddress=).
  • Keep the timeout failure message informative: on failure, include the captured lines in the assertion message.

Acceptance

  • The test only looks at log lines for its own connection.
  • Running the integration tests repeatedly, for example 20 runs of the class next to the other connection tests, shows no failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions