Extract shared STA-thread dispatch helper (#9303)#9326
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #9303 by extracting the duplicated Windows STA/apartment-thread dispatch pattern into a shared internal helper in MSTestAdapter.PlatformServices, and then routing the existing adapter execution paths through that helper to keep behavior consistent (thread naming, warnings, and async bridging).
Changes:
- Introduces
StaThreadHelperto centralize “run on requested apartment state if needed” logic (plus a dedicated STA runner used byTestExecutionManager). - Refactors
TestClassInfoclass initialize/cleanup andMSTestExecutorentry-point execution to use the shared helper. - Simplifies the STA dispatch code path in
TestExecutionManagerby delegating toStaThreadHelper.RunOnStaThreadAsync.
Show a summary per file
| File | Description |
|---|---|
| src/Adapter/MSTestAdapter.PlatformServices/Helpers/StaThreadHelper.cs | Adds shared helper methods for apartment-thread dispatch and STA-thread execution bridging. |
| src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.cs | Replaces inline STA thread/TCS block with StaThreadHelper.RunOnStaThreadAsync. |
| src/Adapter/MSTestAdapter.PlatformServices/Execution/TestClassInfo.Initializer.cs | Routes STATestClass class-initialize execution through RunOnApartmentThreadIfNeededAsync. |
| src/Adapter/MSTestAdapter.PlatformServices/Execution/TestClassInfo.Cleanup.cs | Routes STATestClass class-cleanup execution through RunOnApartmentThreadIfNeededAsync. |
| src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs | Uses the shared helper for entry-point apartment dispatch and Windows-only STA warning. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔍 Build Failure AnalysisSummary — The build of
Root cause: Stale XLF —
|
| Resource key | Value |
|---|---|
Try |
try {0} |
Retried |
retried |
RunningTestsFrom |
Running tests from |
DiscoveringTestsFrom |
Discovering tests from |
Error |
error |
DiscoveredTestsInAssembly |
Discovered {0} tests in assembly |
DiscoveredTestsSummarySingular |
Discovered {0} tests. |
DiscoveredTestsSummary |
Discovered {0} tests in {1} assemblies. |
Affected errors (3× same message, one per TFM):
Microsoft.DotNet.XliffTasks.targets:84—'OutputDevice/Terminal/xlf/TerminalResources.cs.xlf' is out-of-date with 'OutputDevice/Terminal/TerminalResources.resx'- Project:
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj
- Project:
Cascading failure:
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj— failed (1.1s) because it depends onMicrosoft.Testing.Platform.
Proposed fix (for future PRs in this situation):
After merging or rebasing onto a base branch that updated a .resx file, regenerate all XLF files:
dotnet msbuild src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj /t:UpdateXlfThen commit the updated xlf/*.xlf files. Per repo guidelines, never hand-edit XLF files directly.
Build overview
Build: FAILED
Duration: 75.3s
MSBuild: 18.7.0-preview
Projects: 46 Errors: 4 Warnings: 0
Failed projects:
✗ Build.proj (75.1s)
✗ NonWindowsTests.slnf (47.7s)
✗ Microsoft.Testing.Extensions.AzureDevOpsReport.csproj (1.1s)
All MSBuild errors (4)
| Code | Project | File | Message |
|---|---|---|---|
| (XliffTasks) | Microsoft.Testing.Platform.csproj |
Microsoft.DotNet.XliffTasks.targets:84 |
'OutputDevice/Terminal/xlf/TerminalResources.cs.xlf' is out-of-date with 'OutputDevice/Terminal/TerminalResources.resx' |
| (XliffTasks) | Microsoft.Testing.Platform.csproj |
Microsoft.DotNet.XliffTasks.targets:84 |
(same, 2nd TFM) |
| (XliffTasks) | Microsoft.Testing.Platform.csproj |
Microsoft.DotNet.XliffTasks.targets:84 |
(same, 3rd TFM) |
| — | — | — | Build failed. |
🤖 Generated by the Build Failure Analysis workflow using [binlog-mcp]((dev.azure.com/redacted) · commit cef92d8
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Build Failure Analysis workflow. · 560 AIC · ⌖ 22.4 AIC · ⊞ 46.9K · [◷]( · ◷)
Fixes #9303. Extracts a shared internal STA-thread dispatch helper for MSTest adapter execution paths while preserving thread names, warning/error handling, apartment state, and async bridging behavior.