Fix flaky AddIncomingMessageFilter_Multiple_Filters_Execute_In_Order test#1627
Merged
tarekgh merged 1 commit intoJun 4, 2026
Merged
Conversation
…test The test asserts each incoming message filter runs exactly three times, once per message: initialize, notifications/initialized, and tools/list. The initialize and tools/list exchanges are request/response, so awaiting the client calls guarantees their filter passes have completed. The notifications/initialized notification is sent fire-and-forget by the client, so it has no synchronization point and may still be in flight when ListToolsAsync returns, leaving the strict counts at two and failing the test. Add a TaskCompletionSource that the outermost filter completes once it has finished processing the initialized notification, and await it before snapshotting the log. This follows the existing pattern used elsewhere in this file and makes the test deterministic without weakening the strict count assertions.
halter73
approved these changes
Jun 4, 2026
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.
Summary
Fixes a flaky test:
McpServerBuilderExtensionsMessageFilterTests.AddIncomingMessageFilter_Multiple_Filters_Execute_In_Order. It intermittently fails on CI withAssert.Equal() Failure: Expected: 3, Actual: 2(observed on the net8.0 leg, but the race is framework-independent).Root cause
The test asserts each incoming message filter runs exactly three times, once per message:
initialize,notifications/initialized, andtools/list.initializeandtools/listare request/response exchanges, so awaiting the corresponding client calls guarantees their filter passes have completed.notifications/initializedis sent fire-and-forget by the client. It has no synchronization point, so it can still be in flight whenListToolsAsyncreturns. When that happens the strict counts are only2and the test fails.Fix
Add a
TaskCompletionSourcethat the outermost filter completes once it has finished processing the initialized notification, and await it before snapshotting the log. This mirrors the existingTaskCompletionSourcepattern already used elsewhere in this test file (AddOutgoingMessageFilter_Can_Send_Additional_Messages), keeps the strict count assertions intact, and introduces no timing-based delays.Verification
McpServerBuilderExtensionsMessageFilterTestsclass passes on net8.0, net9.0, net10.0, and net472 (21/21 each).