Skip to content

Extract shared STA-thread dispatch helper (#9303)#9326

Merged
Evangelink merged 4 commits into
mainfrom
fix/9303-dedup-sta-thread-dispatch
Jun 22, 2026
Merged

Extract shared STA-thread dispatch helper (#9303)#9326
Evangelink merged 4 commits into
mainfrom
fix/9303-dedup-sta-thread-dispatch

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 StaThreadHelper to centralize “run on requested apartment state if needed” logic (plus a dedicated STA runner used by TestExecutionManager).
  • Refactors TestClassInfo class initialize/cleanup and MSTestExecutor entry-point execution to use the shared helper.
  • Simplifies the STA dispatch code path in TestExecutionManager by delegating to StaThreadHelper.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

Evangelink and others added 2 commits June 22, 2026 13:38
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 12:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment thread src/Adapter/MSTestAdapter.PlatformServices/Execution/TestClassInfo.Initializer.cs Outdated
Comment thread src/Adapter/MSTestAdapter.PlatformServices/Execution/TestClassInfo.Cleanup.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink merged commit e31c68e into main Jun 22, 2026
29 of 36 checks passed
@Evangelink
Evangelink deleted the fix/9303-dedup-sta-thread-dispatch branch June 22, 2026 12:37
@Evangelink

Copy link
Copy Markdown
Member Author

🔍 Build Failure Analysis

Summary — The build of Microsoft.Testing.Platform.csproj failed because TerminalResources.cs.xlf was out-of-date with TerminalResources.resx: eight new resource strings added to the .resx by a concurrent base-branch PR were not reflected in the XLF on this branch. Microsoft.Testing.Extensions.AzureDevOpsReport.csproj failed as a downstream cascade.

i️ This PR has already been merged. The XLF was fixed on main by PR #9329 (merged at 12:36Z, 1 minute before this PR merged at 12:37Z). main is currently clean.


Root cause: Stale XLF — TerminalResources.cs.xlf out-of-date with TerminalResources.resx

PR #9294 ("Add orchestrator TestInProgress/TestDiscovered overloads for SDK parity", merged 2026-06-22T10:24Z) added 8 new resource strings to TerminalResources.resx and regenerated the XLF in the same commit. This PR (#9326) was opened at 09:22Z — before #9294 merged — so when the branch later incorporated the updated base branch (which included the new .resx entries), the XLF on the PR branch was not regenerated to match, leaving it stale.

The _UpdateXlf MSBuild target (from Microsoft.DotNet.XliffTasks) performs a strict in-sync check at CI time and fails the build rather than auto-updating, by design.

Missing trans-unit entries in TerminalResources.cs.xlf (present in .resx, absent in 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

Cascading failure:

  • src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj — failed (1.1s) because it depends on Microsoft.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:UpdateXlf

Then 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 · [◷]( · )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code: STA Thread Dispatch Pattern in MSTest Adapter

2 participants