-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
Conversation
JAVA-4770
@@ -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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java
Outdated
Show resolved
Hide resolved
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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.
Changed to 15 to ensure servermonitor runs at least once.
Nit removed
There was a problem hiding this 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?
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java
Outdated
Show resolved
Hide resolved
@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. |
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.
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). |
There was a problem hiding this 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 inassertLogMessageEquality
. - 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()));
driver-core/src/main/com/mongodb/internal/connection/SingleServerCluster.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/connection/DefaultServer.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java
Show resolved
Hide resolved
@@ -295,6 +311,34 @@ private ServerDescription lookupServerDescription(final ServerDescription curren | |||
} | |||
} | |||
|
|||
private ServerDescription openNewConnectionAndGetInitialDescription(final boolean shouldStreamResponses) { |
There was a problem hiding this comment.
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.
JAVA-4770