Honor STAThread entry point for MSTest execution#8469
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Youssef1313
left a comment
There was a problem hiding this comment.
We explicitly don't await the test when running under STA to preserve the STA thread:
I'm not sure what exactly is breaking here and at which point do you lose the STA thread.
|
Okay I think I can see what's going on here. I think the test is written incorrectly and should be changed to use the MSTest configuration. We never well supported |
Move the multi-line parameter list onto the line after the call to ExecuteAsync so StyleCop's SA1116 rule is satisfied. Pure formatting change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves MSTest execution on Windows by honoring an [STAThread] entry-point when no explicit <ExecutionThreadApartmentState> is configured, reducing timing-dependent STA/MTA behavior during MSTest runner execution.
Changes:
- Added centralized “effective apartment state” resolution that prioritizes runsettings, otherwise infers STA on Windows from
[STAThread]on the entry point. - Updated both MSTest execution paths (VSTest adapter and platform services execution manager) to use the effective apartment state.
- Re-enabled and adjusted STA acceptance coverage, and added targeted unit tests for precedence and platform behavior.
Show a summary per file
| File | Description |
|---|---|
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs |
Adds shared effective apartment-state resolution (runsettings override, otherwise infer STA on Windows from entry point). |
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.cs |
Uses the effective apartment state when deciding whether to run work on an STA thread. |
src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs |
Uses the effective apartment state when selecting the “right context” for execution. |
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestSettingsTests.cs |
Adds unit coverage for precedence (configured wins), Windows STA inference, non-Windows behavior, and non-STA entry points. |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STAThreadingTests.cs |
Re-enables and strengthens STA entry-point acceptance scenario (no-runsettings case) and adjusts ExecuteAsync invocation formatting/inputs. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 0
MSTest only honored explicit
<ExecutionThreadApartmentState>configuration, so tests launched from an[STAThread] Maincould fall back to MTA thread-pool execution after async continuations. This made the no-runsettings STA acceptance scenario timing-dependent and flaky in Debug.[STAThread]on the entry assembly entry point impliesSTAon WindowsExecution flow
MSTestExecutor.RunTestsFromRightContextAsyncTestExecutionManager.DefaultFactoryAsyncCoverage