Repository navigation
Enable MSTest/MTP test execution on wasi-wasm (#2196) - #9781
Conversation
Single-threaded WebAssembly runtimes (wasi-wasm / browser-wasm) have no thread pool: Task.Run continuations never execute and blocking waits throw PlatformNotSupportedException. A user-authored async Main is fine as long as the pipeline completes without hopping to a background thread; the blockers were a handful of thread-dependent spots on the run path. Add a single-threaded-wasm detection (RuntimeFeatureHelper.IsMultiThreaded in the platform, RuntimeContext.IsMultiThreaded in the adapter; derived from OperatingSystem.IsWasi()/IsBrowser(), noting net11 RuntimeFeature.IsMultithreadingSupported) and fall back to inline/synchronous execution when threading is unavailable: - AsynchronousMessageBus: inline BlockingConsumerDataProcessor for all consumers. - CountDownEventExtensions.WaitAsync: cooperative poll path (previously browser-only) instead of ThreadPool.RegisterWaitForSingleObject. - AppInsightsProvider: skip the background ingest Task.Run so Dispose does not block. - ShutdownProgressReporter: skip the Task.Run watchdog. - TestExecutionManager.DefaultFactoryAsync: run inline instead of Task.Run. Multi-threaded behavior is unchanged (the fallbacks only trigger on single-threaded wasm). Add WasmExecutionTests acceptance coverage: an always-on build assertion plus a gated end-to-end run under wasmtime (skipped when the wasm-tools workload/wasmtime are absent). Update the WasiPlayground sample README to reflect that execution now works. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enables MSTest/MTP tests to run end-to-end on single-threaded WebAssembly, using wasi-wasm as a headless stand-in for browser-wasm (both share a no-thread-pool execution model), addressing issue #2196. The insight is that a user-authored async Task Main is fine on single-threaded wasm as long as the pipeline never hops to a background thread; the fix adds a runtime capability probe and falls back to inline/synchronous execution at the handful of thread-dependent spots on the run path. All behavioral changes are gated so multi-threaded runtimes are unaffected.
Changes:
- Adds two
IsMultiThreadedcapability probes —RuntimeFeatureHelper(platform) andRuntimeContext(adapter) — derived fromOperatingSystem.IsBrowser()/IsWasi(). - Gates five thread-dependent code paths on the probe: message-bus consumers (force inline), shutdown watchdog (skip), telemetry ingest loop (skip, keep
Disposenon-blocking), countdown-event wait (cooperative poll), and the adapter's per-test task factory (run inline). - Adds
WasmExecutionTestsacceptance coverage (always-on build assertion + gatedwasmtimeend-to-end run) and updates theWasiPlaygroundREADME.
Show a summary per file
| File | Description |
|---|---|
src/Platform/Microsoft.Testing.Platform/Helpers/RuntimeFeatureHelper.cs |
New internal platform-side single-threaded-wasm capability probe. |
src/Adapter/MSTestAdapter.PlatformServices/Helpers/RuntimeContext.cs |
Adds the adapter-side IsMultiThreaded counterpart. |
src/Platform/Microsoft.Testing.Platform/Messages/AsynchronousMessageBus.cs |
Forces inline (BlockingConsumerDataProcessor) consumption on single-threaded wasm. |
src/Platform/Microsoft.Testing.Platform/Services/ShutdownProgressReporter.cs |
Skips the fire-and-forget Task.Run watchdog when threading is unavailable. |
src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs |
Uses Task.CompletedTask instead of the background ingest loop so Dispose's blocking wait is a no-op. |
src/Platform/Microsoft.Testing.Platform/Helpers/CountDownEventExtensions.cs |
Renames browser/non-browser wait paths to single/multi-threaded and routes via the probe (with a scoped CA1416 suppression). |
src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.cs |
Runs the per-test task inline instead of Task.Run on single-threaded wasm. |
test/IntegrationTests/.../WasmExecutionTests.cs |
New acceptance tests: always-on build/entry-point check and a gated wasmtime end-to-end run. |
samples/WasiPlayground/README.md |
Updates status to reflect working end-to-end execution and explains the threading fixes. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 0
- Review effort level: Medium
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review Summary
Solid PR. The single-threaded-wasm detection is clean, the fallbacks are correctly guarded, and the logic inversions from IsBrowser() → IsMultiThreaded are all correct. No blocking or major issues found.
Dimension Verdicts
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ✅ LGTM |
| 2 | Threading & Concurrency | ✅ LGTM |
| 3 | Security & IPC Contract Safety | ⊘ N/A |
| 4 | Public API & Binary Compatibility | ✅ LGTM |
| 5 | Performance & Allocations | ✅ LGTM |
| 6 | Cross-TFM Compatibility | ✅ LGTM |
| 7 | Resource & IDisposable Management | ✅ LGTM |
| 8 | Defensive Coding at Boundaries | ✅ LGTM |
| 9 | Localization & Resources | ⊘ N/A |
| 10 | Test Isolation | ✅ LGTM |
| 11 | Assertion Quality | ✅ LGTM |
| 12 | Flakiness Patterns | ✅ LGTM |
| 13 | Test Completeness & Coverage | ✅ LGTM |
| 14 | Data-Driven Test Coverage | ⊘ N/A |
| 15 | Code Structure & Simplification | ✅ LGTM |
| 16 | Naming & Conventions | ✅ LGTM |
| 17 | Documentation Accuracy | ✅ LGTM |
| 18 | Analyzer & Code Fix Quality | ⊘ N/A |
| 19 | IPC Wire Compatibility | ⊘ N/A |
| 20 | Build Infrastructure & Dependencies | ⊘ N/A |
| 21 | Scope & PR Discipline | ✅ LGTM |
| 22 | PowerShell Scripting Hygiene | ⊘ N/A |
Notes
- CA1416 suppression (
CountDownEventExtensions.cs): Justified and narrowly scoped.RuntimeFeatureHelper.IsMultiThreadedisfalsefor both browser and wasi, soWaitMultiThreadedAsync(annotated[UnsupportedOSPlatform("browser")]) is unreachable on browser. The analyzer can't infer this through the helper, so the pragma is the correct solution. [UnsupportedOSPlatform("browser")]onWaitMultiThreadedAsync: Could additionally be annotated with[UnsupportedOSPlatform("wasi")]for documentary completeness (the method usesThreadPool.RegisterWaitForSingleObjectwhich would also fail on wasi). Low priority since the method is private and the runtime guard already prevents calls on both platforms.- Test asset
Assert.IsTrue(true): This is the wasm test asset, not the acceptance test itself — it intentionally exercises minimal passing assertions to validate the wasm pipeline, not production logic. Acceptable as-is. GenerateWasmAssetAsyncparallel safety: Both test methods use the same asset name"WasmTestProject", butTempDirectory.CreateUniqueDirectorygenerates a random path viaRandomId.Next(), so parallel execution is safe.
No action required — clean to merge.
This comment has been minimized.
This comment has been minimized.
🔍 Build Failure AnalysisSummary — New internal API members ( Root cause: Missing
|
| # | File | Error |
|---|---|---|
| 1 | RuntimeFeatureHelper.cs:9 |
RS0051: Symbol 'Microsoft.Testing.Platform.Helpers.RuntimeFeatureHelper' is not part of the declared API |
| 2 | RuntimeFeatureHelper.cs:29 |
RS0051: Symbol 'static ...RuntimeFeatureHelper.IsMultiThreaded.get -> bool' is not part of the declared API |
| 3 | RuntimeContext.cs:27 |
RS0051: Symbol 'static ...RuntimeContext.IsMultiThreaded.get -> bool' is not part of the declared API (×2, once per TFM) |
Proposed fix
Add the missing entries to three InternalAPI.Unshipped.txt files:
1. src/Platform/Microsoft.Testing.Platform/InternalAPI/InternalAPI.Unshipped.txt
#nullable enable
+Microsoft.Testing.Platform.Helpers.RuntimeFeatureHelper
static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.ReadFields(System.IO.Stream! stream, System.Func<ushort, int, bool>! tryReadField) -> void
static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteListPayload<T>(System.IO.Stream! stream, ushort fieldId, T[]? list, System.Action<System.IO.Stream!, T>! writeItem) -> void
+static Microsoft.Testing.Platform.Helpers.RuntimeFeatureHelper.IsMultiThreaded.get -> bool2. src/Platform/Microsoft.Testing.Platform/InternalAPI/net/InternalAPI.Unshipped.txt — same additions as above.
3. src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt
#nullable enable
+static Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers.RuntimeContext.IsMultiThreaded.get -> boolCascading failures
Microsoft.Testing.Extensions.AzureFoundry.csproj also failed because it depends on Microsoft.Testing.Platform which did not produce a valid output. No additional fix needed — resolving the RS0051 errors fixes it.
Build overview
| Metric | Value |
|---|---|
| Status | ❌ FAILED |
| Duration | 195.2 s |
| Projects | 49 |
| Errors | 5 (4 distinct RS0051 + 1 "Build failed") |
| Warnings | 0 |
Failed projects:
Microsoft.Testing.Platform.csproj— 2 RS0051 errors (newRuntimeFeatureHelperclass + property)MSTestAdapter.PlatformServices.csproj— 2 RS0051 errors (newRuntimeContext.IsMultiThreaded, one per TFM)Microsoft.Testing.Extensions.AzureFoundry.csproj— cascading (depends on MTP)Build.proj/NonWindowsTests.slnf— top-level orchestration failure
All MSBuild errors (5)
| Code | Project | File:Line | Message |
|---|---|---|---|
| RS0051 | Microsoft.Testing.Platform | RuntimeFeatureHelper.cs:9 |
Symbol RuntimeFeatureHelper is not part of the declared API |
| RS0051 | Microsoft.Testing.Platform | RuntimeFeatureHelper.cs:29 |
Symbol RuntimeFeatureHelper.IsMultiThreaded.get -> bool is not part of the declared API |
| RS0051 | MSTestAdapter.PlatformServices | RuntimeContext.cs:27 |
Symbol RuntimeContext.IsMultiThreaded.get -> bool is not part of the declared API |
| RS0051 | MSTestAdapter.PlatformServices | RuntimeContext.cs:27 |
Symbol RuntimeContext.IsMultiThreaded.get -> bool is not part of the declared API (2nd TFM) |
| — | Build.proj | — | Build failed. |
🤖 Generated by the Build Failure Analysis workflow using binlog-mcp · commit 99deca0
🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · 164.8 AIC · ⌖ 7.99 AIC · ⊞ 7.3K · [◷]( · ◷)
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · 164.8 AIC · ⌖ 7.99 AIC · ⊞ 7.3K · ◷
- Declare RuntimeFeatureHelper and RuntimeContext.IsMultiThreaded in the
InternalAPI.Unshipped.txt files (fixes the RS0016/RS0051 build failure).
- WasiPlayground: drop AddAzureDevOpsProvider (its HttpClient sets
AutomaticDecompression, unsupported by the wasi HttpClientHandler), mirroring
the existing hang-dump exclusion, so the sample runs green on wasi.
- README: show the actual WasiPlayground sample output (DummyFramework, 1 passing
test) instead of the acceptance-test asset output, and note the extension-level
wasi limitations.
- Annotate CountDownEventExtensions.WaitMultiThreadedAsync with
[UnsupportedOSPlatform("wasi")] for documentary completeness.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
.editorconfig enforces charset = utf-8-bom for *.cs; the two newly added files (RuntimeFeatureHelper.cs, WasmExecutionTests.cs) were missing it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
# Conflicts: # src/Platform/Microsoft.Testing.Platform/InternalAPI/InternalAPI.Unshipped.txt
This comment has been minimized.
This comment has been minimized.
Short-circuit LogEventAsync when !RuntimeFeatureHelper.IsMultiThreaded so events are not queued into the unbounded channel with no consumer draining it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🧪 Test quality grade — PR #9781
This advisory comment was generated automatically. Grades are heuristic
|
Summary
Enables running MSTest tests end-to-end in WebAssembly from a console host, using
wasi-wasmas a headless proxy forbrowser-wasm(both share the same single-threaded execution model). Fixes the core platform work tracked by #2196.The wasm expert's guidance was the key insight:
async Mainis fine; threads are not. A user-authoredasync Task Maincompletes cleanly on single-threaded wasm as long as the pipeline never hops to a background thread — the compiler's synthetic entry point only blocks (GetAwaiter().GetResult()) when the awaited task hasn't already completed. The real blockers were a handful of thread-dependent spots on the run path, since single-threaded wasm has no thread pool (Task.Runcontinuations never execute and blocking waits throwPlatformNotSupportedException).Approach
Add a single-threaded-wasm detection and fall back to inline/synchronous execution when threading is unavailable:
RuntimeFeatureHelper.IsMultiThreaded(platform) andRuntimeContext.IsMultiThreaded(adapter) — derived fromOperatingSystem.IsWasi()/IsBrowser()(available since .NET 8). Both document that .NET 11'sRuntimeFeature.IsMultithreadingSupported(dotnet/runtime#77541) is the future canonical API.Fixes (all gated on single-threaded wasm — multi-threaded behavior is unchanged)
AsynchronousMessageBusBlockingConsumerDataProcessorfor all consumers (theTask.Runbackground consumer loop never ran).CountDownEventExtensions.WaitAsyncThreadPool.RegisterWaitForSingleObject, whose callback never fires on wasi.AppInsightsProviderTask.RunsoDispose's blocking.Wait()is a no-op.ShutdownProgressReporterTask.Runwatchdog.TestExecutionManager.DefaultFactoryAsyncTask.Run(parallelism is irrelevant on a single thread).Tests
New
WasmExecutionTestsacceptance coverage:WasmBuild_GeneratesTestingPlatformEntryPoint— always-on; asserts awasi-wasmMSTest project builds and the MTP entry point is generated (only needs thewasi-experimentalworkload the bootstrap installs).WasmExecution_RunsTestsUnderWasmtime— publishes a real MSTestwasi-wasmproject and runs it end-to-end underwasmtime, asserting the passing tests report success, the failing test is reported failed, and there's noPlatformNotSupportedException. Skipped (inconclusive) when thewasm-toolsworkload orwasmtimeis unavailable, so it only runs where the wasm runtime exists.Validation
wasmtime(2 succeeded, 1 failed, non-zero exit) and skip cleanly without it.Test run summary: Passed!, exit code 0.Follow-up (not in this PR)
The gated execution test skips everywhere without the toolchain. To exercise it in CI, a Linux leg would need to install the
wasm-toolsworkload +wasmtime. Happy to wire that pipeline change in a follow-up.