Fix flaky RefreshChangingUserIdentifierClosesConnection test - #68096
Open
BrennanConroy wants to merge 1 commit into
Open
Fix flaky RefreshChangingUserIdentifierClosesConnection test#68096BrennanConroy wants to merge 1 commit into
BrennanConroy wants to merge 1 commit into
Conversation
The Long Polling variant of this test is flaky. When the refresh changes the user identifier the server aborts the connection, and on dispose the client sends a best-effort DELETE carrying the refreshed token. That DELETE races the server's teardown: if the connection hasn't been removed from the manager yet the server rejects it with 403 and LongPollingTransport logs ErrorSendingDeleteRequest, failing VerifyNoErrorsScope. Once the connection is removed the DELETE gets a benign 404, so whether the error is logged depends purely on timing. Allow-list that specific teardown error so the timing race no longer fails the test. The connection is already closed either way, which the test still asserts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes flakiness in the SignalR C# client functional test HubConnectionTests.RefreshChangingUserIdentifierClosesConnection when running over Long Polling by allow-listing an expected teardown-time log event that can race with server connection cleanup.
Changes:
- Add a logger name constant for
LongPollingTransportto keep expected-error filters precise and consistent. - Update the refresh test to pass a narrowly-scoped
expectedErrorspredicate that ignoresLongPollingTransport’sErrorSendingDeleteRequestduring disposal teardown.
Show a summary per file
| File | Description |
|---|---|
| src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs | Adds a constant for the Long Polling transport logger name used by test log filtering. |
| src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.AuthenticationRefresh.cs | Adds a narrowly-scoped expectedErrors filter to ignore a known Long Polling teardown race (ErrorSendingDeleteRequest). |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
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 flakiness in the Long Polling variant of
HubConnectionTests.RefreshChangingUserIdentifierClosesConnection.Root cause
When the refresh changes the user identifier, the server aborts the connection. On dispose, the Long Polling client sends a best-effort
DELETEcarrying the refreshed (userB) token. ThatDELETEraces the server's teardown:RejectIfUserChangedAsyncreturns 403 Forbidden (the connection is still bound to userA), andLongPollingTransportlogsErrorSendingDeleteRequestat Error level — which fails the test'sVerifyNoErrorsScope.DELETEgets a benign 404 and is logged at Debug.So whether the error is logged depends purely on timing. The connection is torn down by the abort either way (the test still asserts
Disconnected), so this teardown error is expected and harmless.Only this test hits the race, because it's the only refresh test that changes the SignalR
UserIdentifierwhile running over real Long Polling. WebSockets/SSE don't send an authenticatedDELETEon dispose, and the other refresh tests keep the same user so their cleanupDELETEstays authorized.Fix
Allow-list that one specific teardown error (
LongPollingTransport/ErrorSendingDeleteRequest) via the existingexpectedErrorsfilter onStartServer, matching the established pattern used by sibling refresh tests. The filter is deliberately narrow so genuine failures still surface.Test-only change. Verified by running all three transports (3/3 pass) and stressing the Long Polling variant (6/6 pass).