[HTTP] Fix HttpListener tests blocking xunit workers (#21870)#124469
Merged
ManickaP merged 1 commit intodotnet:mainfrom Feb 17, 2026
Merged
[HTTP] Fix HttpListener tests blocking xunit workers (#21870)#124469ManickaP merged 1 commit intodotnet:mainfrom
ManickaP merged 1 commit intodotnet:mainfrom
Conversation
Replace blocking patterns that cause deadlocks when xunit parallel execution is enabled: - Replace .Result with await on task completions - Replace Task.Run(() => GetContext()) with GetContextAsync() - Replace Task.Run(() => Receive()) with ReceiveAsync() - Convert synchronous Socket.Send() to SendAsync() in async methods - Re-enable parallel test execution by removing DisableTestParallelization and MaxParallelThreads = 1 - Fix disposal order in HttpListenerRequestTests to close the client socket before the listener, avoiding a 1s linger timeout per test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates System.Net.HttpListener tests to avoid blocking xUnit worker threads (e.g., .Result, Task.Run around sync socket APIs), so the suite can run reliably when xUnit parallel execution is enabled.
Changes:
- Replace blocking wait patterns with
await, and replaceTask.Run(() => ...)wrappers with native async APIs (GetContextAsync, socket async APIs). - Convert synchronous socket sends to
SendAsyncinside async test flows. - Remove the assembly-level
DisableTestParallelization/MaxParallelThreads = 1restriction and adjust disposal ordering to reduce per-test timeouts.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Net.HttpListener/tests/XUnitAssemblyAttributes.cs | Removes forced disabling of parallelization at the assembly level. |
| src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs | Switches send/receive to async and avoids .Result (but currently has a Task/ValueTask mismatch). |
| src/libraries/System.Net.HttpListener/tests/HttpResponseStreamTests.cs | Uses SendAsync instead of blocking Send in async tests. |
| src/libraries/System.Net.HttpListener/tests/HttpRequestStreamTests.cs | Uses SendAsync instead of blocking Send in async tests. |
| src/libraries/System.Net.HttpListener/tests/HttpListenerResponseTests.cs | Uses SendAsync instead of blocking Send when establishing contexts. |
| src/libraries/System.Net.HttpListener/tests/HttpListenerRequestTests.cs | Fixes disposal order and replaces .Result with await; uses SendAsync in request helper. |
| src/libraries/System.Net.HttpListener/tests/HttpListenerContextTests.cs | Uses SendAsync instead of blocking Send when establishing contexts. |
| src/libraries/System.Net.HttpListener/tests/HttpListenerAuthenticationTests.cs | Removes Task.Run(() => GetContext()) + cancellation token pattern; uses GetContextAsync and await for client responses. |
src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs
Show resolved
Hide resolved
Member
Author
|
/ba-g #124515 |
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.
Replace blocking patterns that cause deadlocks when xunit parallel execution is enabled:
Fixes #21870