Skip to content

JAVA-6174 Fix sdam eventType to assert serverDescriptionChangedEvent#1978

Merged
nhachicha merged 2 commits into
mongodb:backpressurefrom
nhachicha:nh/backpressure/test_runner
May 22, 2026
Merged

JAVA-6174 Fix sdam eventType to assert serverDescriptionChangedEvent#1978
nhachicha merged 2 commits into
mongodb:backpressurefrom
nhachicha:nh/backpressure/test_runner

Conversation

@nhachicha
Copy link
Copy Markdown
Collaborator

@nhachicha nhachicha commented May 20, 2026

- 3-bucket partition in UnifiedTest.java
- ServerDescriptionChangedEvent support in EventMatcher/ContextElement
- waitForEvent connectionClosedEvent support
- Unskip backpressure-server-description-unchanged spec test
Copy link
Copy Markdown
Contributor

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

Updates the unified test runner’s SDAM event handling so serverDescriptionChangedEvent is recognized and asserted separately from heartbeat events, enabling previously skipped SDAM/backpressure spec coverage to run.

Changes:

  • Unskips the SDAM backpressure spec test backpressure-server-description-unchanged-on-min-pool-size-population-error.
  • Refactors SDAM expectEvents comparison to 3-way partition expected events into topology vs serverDescriptionChangedEvent vs heartbeat events.
  • Extends event type normalization and context rendering to support ServerDescriptionChangedEvent.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java Removes the skip for the backpressure SDAM spec file so it runs again.
driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java Partitions SDAM expected events into topology / serverDescriptionChanged / heartbeat and asserts them via the appropriate listeners.
driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java Broadens getEventType to include all Server* events and adds a note about awaited matching limitations.
driver-sync/src/test/functional/com/mongodb/client/unified/ContextElement.java Ensures ServerDescriptionChangedEvent can be rendered without assuming an awaited field.
Comments suppressed due to low confidence (1)

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

  • serverMonitorEventMatches is now also exercised for ServerDescriptionChangedEvent (via SDAM event comparisons), but it does not validate serverDescriptionChangedEvent-specific contents like newDescription (it only checks awaited). This makes SDAM event assertions weaker than the existing serverDescriptionChangedEventMatches used by waitForEvent/assertEventCount. Consider either extending this matcher to handle ServerDescriptionChangedEvent (including content validation) or ensuring ServerDescriptionChangedEvent expectations are routed to a separate matcher that uses serverDescriptionChangedEventMatches.
    private static <T> boolean serverMonitorEventMatches(
            final BsonDocument expectedEventContents,
            final T event,
            @Nullable final AssertionContext context) {
        if (expectedEventContents.size() > 1) {
            throw new UnsupportedOperationException("Matching for the following event is not implemented " + expectedEventContents.toJson());
        }
        // TODO JAVA-6174: 'awaited' matching is only supported for ServerHeartbeat* events; a non-empty
        // 'serverDescriptionChangedEvent' with an 'awaited' field will fail in getAwaitedFromServerMonitorEvent.
        if (expectedEventContents.containsKey("awaited")) {
            boolean expectedAwaited = expectedEventContents.getBoolean("awaited").getValue();
            boolean actualAwaited = getAwaitedFromServerMonitorEvent(event);
            boolean awaitedMatches = expectedAwaited == actualAwaited;
            if (context != null) {
                assertTrue(context.getMessage("Expected `awaited` to match"), awaitedMatches);
            }
            return awaitedMatches;
        }
        return true;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Route ServerDescriptionChangedEvent to serverDescriptionChangedEventMatches
so 'newDescription' content is actually verified and 'awaited' on a
non-heartbeat event no longer crashes in getAwaitedFromServerMonitorEvent.
} else if (eventClassName.startsWith("Connection")) {
return eventClassName.replace("Connection", "connection");
} else if (eventClassName.startsWith("ServerHeartbeat")) {
} else if (eventClassName.startsWith("Server")) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

broadens the event-type mapping from only heartbeat events to all server events.

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

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

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

@nhachicha nhachicha changed the title JAVA-6174: Fix sdam eventType to assert serverDescriptionChangedEvent JAVA-6174 Fix sdam eventType to assert serverDescriptionChangedEvent May 21, 2026
@nhachicha nhachicha requested a review from rozza May 21, 2026 00:55
@nhachicha nhachicha marked this pull request as ready for review May 21, 2026 00:55
@nhachicha nhachicha requested a review from a team as a code owner May 21, 2026 00:55
Copy link
Copy Markdown
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

My code review picked up:

Broadening startsWith("ServerHeartbeat") → startsWith("Server") now matches ServerOpeningEvent, ServerClosedEvent, and ServerDescriptionChangedEvent. While the transformation (lowercase first char) produces valid camelCase names for all, this changes fallback behavior from throwing UnsupportedOperationException to silently producing an event type string for events not previously handled. If ServerOpeningEvent or ServerClosedEvent ever accidentally flow through this path, the test would silently produce incorrect assertions rather than failing fast.

I think thats probably a caveat to a lot of the unified test code. Its potentially fragile to future changes.

So LGTM - the only concerns I have are about the complexity of this code in general!

@nhachicha nhachicha merged commit f5f50b8 into mongodb:backpressure May 22, 2026
53 checks passed
@nhachicha nhachicha deleted the nh/backpressure/test_runner branch May 22, 2026 12:50
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