-
Notifications
You must be signed in to change notification settings - Fork 291
Add UseSTASynchronizationContext to STATestMethod #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a UseSTASynchronizationContext property to STATestMethodAttribute to enable preserving the STA thread context for async continuations. When enabled, the attribute creates a custom SynchronizationContext that ensures async continuations run on the same STA thread, which is useful for testing UI components that require STA threading.
Changes:
- Introduced
SingleThreadedSTASynchronizationContextclass that manages a dedicated STA thread and routes all operations to it - Added
UseSTASynchronizationContextproperty toSTATestMethodAttributewith default value offalse - Modified
STATestMethodAttribute.ExecuteAsyncto conditionally use the new synchronization context - Added tests to verify both default behavior (no sync context) and new behavior (with sync context)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/TestFramework/TestFramework/Attributes/TestMethod/SingleThreadedSTASynchronizationContext.cs |
New internal class that implements a custom SynchronizationContext with a dedicated STA thread for routing operations |
src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs |
Added UseSTASynchronizationContext property and modified ExecuteAsync to optionally use the new sync context |
src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt |
Added public API entries for the new property getter and setter |
test/UnitTests/MSTest.SelfRealExamples.UnitTests/STATestMethodSyncContext.cs |
Added integration tests verifying both default and new behavior |
src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs
Show resolved
Hide resolved
...TestFramework/TestFramework/Attributes/TestMethod/SingleThreadedSTASynchronizationContext.cs
Show resolved
Hide resolved
There was a problem hiding this 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 4 comments.
Fixes #5729