Skip to content

Added logging specification tests #1740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Added logging specification tests #1740

wants to merge 15 commits into from

Conversation

rozza
Copy link
Member

@rozza rozza commented Jun 16, 2025

@rozza rozza requested a review from Copilot June 16, 2025 13:33
Copilot

This comment was marked as resolved.

@rozza rozza requested a review from Copilot June 16, 2025 13:44
Copilot

This comment was marked as outdated.

@@ -58,9 +58,9 @@ public SingleServerCluster(final ClusterId clusterId, final ClusterSettings sett
// synchronized in the constructor because the change listener is re-entrant to this instance.
// In other words, we are leaking a reference to "this" from the constructor.
withLock(() -> {
server.set(createServer(settings.getHosts().get(0)));
publishDescription(ServerDescription.builder().state(CONNECTING).address(settings.getHosts().get(0))
Copy link
Member Author

@rozza rozza Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests expect the toplogy description changed to connecting & unknown to be logged before the starting the server monitor log message.

Creating the server first meant that they were the wrong way around.

@rozza rozza requested review from a team and katcharov and removed request for a team June 16, 2025 15:56
@rozza rozza marked this pull request as ready for review June 17, 2025 13:45
@rozza rozza requested a review from a team as a code owner June 17, 2025 13:45
Copy link
Collaborator

@katcharov katcharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -336,7 +336,7 @@ public <T> void waitForServerMonitorEvents(final String client, final Class<T> e
BsonDocument expectedEventContents = getEventContents(expectedEvent);
try {
serverMonitorListener.waitForEvents(expectedEventType,
event -> serverMonitorEventMatches(expectedEventContents, event, null), count, Duration.ofSeconds(10));
event -> serverMonitorEventMatches(expectedEventContents, event, null), count, Duration.ofSeconds(30));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to 15 - I just wanted to ensure that the server monitor through runs at least once. I think it defaults to every 10 seconds.

rozza added 2 commits June 19, 2025 16:58
Changed to 15 to ensure servermonitor runs at least once.
@jyemin jyemin self-requested a review June 19, 2025 22:48
Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely, when I run the tests locally, both the sync and reactive runners consistently fail the standalone-logging: Topology lifecycle test.

java.lang.AssertionError: Expected BSON values to be equal

Assertion Context:

Value Matching Context:
   Key: message
   Expected value:
      BsonString{value='Topology description changed'}
   Actual value:
      BsonString{value='Stopped server monitoring'}

I imagine you're not seeing that?

@rozza
Copy link
Member Author

rozza commented Jun 23, 2025

@jyemin - I do see it locally. I recall it as the result of a race condition - the test fails before the description is changed.

I'll review again and see if there is a way to reduce the flakyness. As 5 of the 6 failures hit a similar race when heartbeats are expected to fail.

rozza added 6 commits June 24, 2025 13:07
Previous failing Failing heartbeat test showed that multiple heartbeat started calls
but no success or failure calls.
When openining a socket that throws an exception the heartbeat started message
is created but no heartbeat failed message.
@rozza rozza marked this pull request as draft June 25, 2025 18:01
@rozza rozza marked this pull request as ready for review June 26, 2025 14:24
@rozza
Copy link
Member Author

rozza commented Jun 26, 2025

Flaky tests fixed and modifications removed.

Final bug I introduced in JAVA-5230 - where opening the connection issues a heartbeat started event but if that errored there wasn't a corresponding heartbeat failed event.

Build looking happier now (I did have to restart some non related failures).

@rozza rozza requested review from katcharov, jyemin and Copilot June 26, 2025 14:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements logging specification tests (JAVA-4770) by updating the unified test framework to support filtering and ignoring specific log messages, and introduces structured logging in cluster and server monitor classes.

  • Remove skips for logging tests and add ignoreMessages support in assertLogMessageEquality.
  • Refactor and extend LogMatcher, ContextElement, and unified tests to handle ignored log entries.
  • Add structured logging methods in DefaultServerMonitor, adjust topology monitoring logs, and update related classes.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java Removed skipJira entries for logging tests
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java Added ignoreMessages parameter and updated assertLogMessageEquality
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java Filter test data to only serverMonitoringMode scenarios
driver-sync/src/test/functional/com/mongodb/client/unified/LogMatcher.java Support ignoreMessages, extract helper methods
driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java Increased timeout and refined failure message handling
driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java Updated to use logMessageAsDocument helper
driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java Removed stray blank import
driver-core/src/main/com/mongodb/internal/logging/LogMessage.java Added AWAITED enum entry
driver-core/src/main/com/mongodb/internal/connection/SingleServerCluster.java Reordered server.set and publishDescription
driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java Changed close logging to logTopologyMonitoringStopping
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java Introduced structured logging methods and refactored heartbeat logic
driver-core/src/main/com/mongodb/internal/connection/DefaultServer.java Added unused StructuredLogger import and field
driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java Updated topology monitoring log methods
Comments suppressed due to low confidence (1)

driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java:344

  • Using the exception message as a resource key may produce unclear failure messages if the key doesn't exist. Consider using a fixed context message or passing the exception message directly to fail().
            fail(context.getMessage(e.getMessage()));

@@ -295,6 +311,34 @@ private ServerDescription lookupServerDescription(final ServerDescription curren
}
}

private ServerDescription openNewConnectionAndGetInitialDescription(final boolean shouldStreamResponses) {
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The new openNewConnectionAndGetInitialDescription method duplicates logic from lookupServerDescription. Consider refactoring shared parts to reduce duplication.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants