Repository navigation
Ensure serverHeartbeatEvent is sent before opening a connection - #1715
Merged
Merged
Conversation
Added Heartbeat prose test Migrated DefaultServerMonitorSpecification to JUnit 5. JAVA-5230
rozza
requested review from
a team,
Copilot and
katcharov
and removed request for
a team
May 22, 2025 09:18
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the legacy Groovy DefaultServerMonitorSpecification to JUnit 5 tests and refines the heartbeat-started event emission in DefaultServerMonitor.
- Introduced
DefaultServerMonitorTest.javawith new JUnit 5 tests covering success, failure, and ordering of heartbeat events before socket connect. - Removed the old
DefaultServerMonitorSpecification.groovy. - Updated
DefaultServerMonitor.javato add aVisibleForTestingaccessor and de-duplicateserverHeartbeatStartedevents using a new flag.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| driver-core/src/test/unit/com/mongodb/internal/connection/DefaultServerMonitorTest.java | Added JUnit 5 tests for heartbeat events and ordering before connection open |
| driver-core/src/test/unit/com/mongodb/internal/connection/DefaultServerMonitorSpecification.groovy | Removed legacy Groovy-based spec after migrating tests to JUnit 5 |
| driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java | Added getServerMonitor() for testing, alreadyLoggedHeartBeatStarted flag, and refined heartbeat-started logic |
Comments suppressed due to low confidence (2)
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java:161
- [nitpick] Consider renaming 'alreadyLoggedHeartBeatStarted' to 'alreadyLoggedHeartbeatStarted' to follow consistent camelCase for the term 'heartbeat'.
private volatile boolean alreadyLoggedHeartBeatStarted = false;
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java:224
- Add a unit test that simulates multiple heartbeat cycles to verify the 'alreadyLoggedHeartBeatStarted' flag behavior and ensure only one 'ServerHeartbeatStartedEvent' is emitted per cycle.
boolean shouldStreamResponses = shouldStreamResponses(currentServerDescription);
rozza
commented
May 22, 2025
…ultServerMonitorTest.java
rozza
marked this pull request as draft
May 22, 2025 10:56
rozza
marked this pull request as ready for review
May 22, 2025 12:23
katcharov
reviewed
May 23, 2025
katcharov
approved these changes
May 27, 2025
| */ | ||
| @Test | ||
| @Ignore | ||
| @Ignore("JAVA-4484 - events are not guaranteed to be delivered in order") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added Heartbeat prose test
Migrated DefaultServerMonitorSpecification to JUnit 5.
JAVA-5230