Skip to content

Capture unit-test hang dumps and bound CI test steps - #41038

Merged
kubaflo merged 2 commits into
net11from
simonrozsival-unit-test-hang-dumps
Dec 2, 2026
Merged

kubaflo merged 2 commits into
net11from
simonrozsival-unit-test-hang-dumps

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 637ebab0d315691e81c07ecbc392ee81cf120a8b

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ 20 pipeline regression checks passed.
↑ macOS arm64/.NET 11 smoke test produced a mini dump and named-test log, then exited nonzero; normal execution passed.
↓ Full MAUI test matrix, Azure task timeout behavior and artifact upload remain unverified.
Diagnosis confidence 9/10 ↑ Existing unit-test invocations lack HangDump and a step deadline; the job-wide timeout prevents later tests from running.
↓ This diagnoses the missing diagnostics, not the underlying intermittent Core test hang.
Evidence fit 8/10 ↑ Reported silent Core.UnitTests stall matches the unbounded template invocation; induced inactivity yielded the intended diagnostics.
↓ The original intermittent stall was not reproduced locally.

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

Release/macOS unit-test runs intermittently stop after starting Core.UnitTests and remain silent until the 240-minute job deadline. The current direct-MTP unit-test template, introduced by #40763, has neither a hang collector nor a per-invocation deadline. Consequently, the hang is unidentified and later suites never run.

  • Opt unit-test invocations into Microsoft.Testing.Extensions.HangDump, pinned to the existing MTP version (2.5.1). The new MSBuild opt-in keeps ordinary builds and native device runners unchanged.
  • Enable --hangdump --hangdump-timeout 10m --hangdump-type Mini for both the shared project loop and Windows-only BlazorWebView unit tests. MTP captures a dump, records in-progress test names when the host can respond, and terminates the hung host. Mini dumps retain stacks while limiting artifact size.
  • Add a 30-minute task deadline through the shared dotnet wrapper, leaving its other callers at the existing job-inherited default. This also bounds restore/build hangs, which the MTP watchdog cannot cover.
  • Preserve the existing succeededOrFailed() execution and always() validation/publication paths. Dumps and companion .log files are written beneath the existing per-project results directory, so the existing UnitTests-<job>-<configuration>-<attempt> artifact publishes them alongside TRX/binlogs.
  • Add pipeline regression checks and document how to retrieve the diagnostics. A fallback task timeout may not produce a dump, and a completely unresponsive test host may not supply test names.

Scope: this identifies future hangs; it does not claim to fix or identify the original hanging Core test. No speculative animation-test changes are included.

Main also needs this change: the live main unit-test template matched net11 byte-for-byte when checked. This PR targets the explicitly assigned net11; forward-port the diagnostics to main as well.

Validation

  • pwsh -NoProfile -Command 'Invoke-Pester -Path ./eng/pipelines/ci.Tests.ps1 -Output Detailed -CI' — passed, 20/20.
  • dotnet msbuild src/Core/tests/UnitTests/Core.UnitTests.csproj -nologo -p:EnableUnitTestHangDump=true -getItem:PackageReference — passed; exactly one HangDump reference at 2.5.1. The same evaluation without the opt-in excludes HangDump.
  • Both changed YAML templates parsed successfully; git diff --check passed.
  • Isolated temporary xUnit 4.0.2/MTP 2.5.1, .NET 11 Release/macOS arm64 smoke fixture (not committed): DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test --project HangDumpSmoke.csproj --configuration Release --report-trx --hangdump --hangdump-timeout 10m --hangdump-type Mini --results-directory results/pass — passed, 1/1.
  • Same fixture, deliberately blocked test: HANGDUMP_SMOKE_HANG=1 DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test --project HangDumpSmoke.csproj --configuration Release --no-build --report-trx --hangdump --hangdump-timeout 10s --hangdump-type Mini --results-directory results/hang — expected failure, exit 7; console and companion log named HangTests.IdentifiesTheHangingTest; nonempty mini dump produced. Only the timeout was shortened to exercise the watchdog promptly.
  • Full MAUI unit-test matrix, local reproduction of the intermittent Core hang, Windows/Linux dump collection and actual Azure publication were not run.

Issues Fixed

No linked issue. Addresses missing diagnostics and unbounded unit-test steps observed during nightly CI triage; the underlying hanging test remains unknown.

Let AI finish this PR

  • Let the MAUI agent address review feedback and fix remaining issues on this PR. Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits.

Enable MTP HangDump for unit-test pipeline invocations, retain named-test diagnostics with existing result artifacts, and add a per-step timeout before the job-wide limit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it label Dec 2, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress label Dec 2, 2026

@github-actions github-actions Bot 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.

Expert Review — 1 finding

Reviewed commit 637ebab.

See inline comments for details.

Comment thread Directory.Build.targets Resolved
@github-actions github-actions Bot added s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) and removed s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress labels Dec 2, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress and removed s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) labels Dec 2, 2026

@github-actions github-actions Bot 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.

Expert Review — No more findings

Reviewed commit 7c68860.

@github-actions github-actions Bot added s/autopilot-testing MAUI Autopilot: relevant UI/device tests are being selected or run and removed s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Selected Tests

Result NOTHING TO RUN Platforms none Tests 0 UI, 0 device Commit 7c688603


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ➖ nothing to run none —
Device tests ➖ nothing to run none —
🧪 UI tests — nothing to run

ℹ️ The AI found no changes relevant to UI tests, so no maui-pr-uitests run was queued.

GPT-6.2 Sol: Unit-test hang diagnostics and deadlines leave PR UI tests unchanged.
MAI Code 2: Unit-test pipeline diagnostics and timeout changes; no UI or device tests are affected.

🧪 Running — nothing

No UI tests run for this PR.

🧪 Device tests — nothing to run

ℹ️ The AI found no changes relevant to device tests, so no maui-pr-devicetests run was queued.

GPT-6.2 Sol: Unit-test CI changes leave Helix device test builds and execution unchanged.
MAI Code 2: Unit-test infrastructure changes do not affect native device test behavior.

🧪 Running — nothing

No device tests run for this PR.

⏭️ Skipped — what neither suite runs

UI tests — 77 categories, 4 platforms

Platforms not run: Android, iOS, MacCatalyst, Windows

Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.

Device tests — 105 categories, 4 platforms

Platforms not run: Android, iOS, MacCatalyst, Windows

Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS — —
MacCatalyst — —
Windows — —

GPT-6.2 Sol — Unit-test hang diagnostics and deadlines leave PR UI tests unchanged.

  • HangDump is opt-in in Directory.Build.targets and UITest.NUnit.Tests.csproj.
  • Only the unit-test stage sets a deadline; the shared wrapper keeps its no-timeout default.
  • No UI test cases or app code changed.

MAI Code 2 — Unit-test pipeline diagnostics and timeout changes; no UI or device tests are affected.

  • Changes are confined to unit-test package opt-in, stage arguments, task timeout handling, regression tests, and development docs.
  • EnableUnitTestHangDump is opt-in and only enabled by the unit-test pipeline, so default UI/device builds remain unchanged.
  • The UI and device test suites are not invoked by the modified stage, so neither suite needs a run.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS — —
MacCatalyst — —
Windows — —

GPT-6.2 Sol — Unit-test CI changes leave Helix device test builds and execution unchanged.

  • HangDump and the 30-minute deadline are enabled only by the unit-test stage.
  • The shared wrapper keeps its no-timeout default for other callers.
  • No device tests, shared device-test infrastructure, or product code changed.

MAI Code 2 — Unit-test infrastructure changes do not affect native device test behavior.

  • The patch changes only unit-test hang-dump collection, per-step deadlines, pipeline regression checks, and documentation.
  • HangDump package references are conditional on an opt-in enabled only for the unit-test stage.
  • No device-test source, product runtime/handler code, or device pipeline is changed.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@github-actions github-actions Bot added s/autopilot-waiting-for-maintainer-review MAUI Autopilot finished: expert review clean and tests passed; waiting for maintainer review and removed s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it s/autopilot-testing MAUI Autopilot: relevant UI/device tests are being selected or run labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

MAUI Autopilot — Ready for maintainer review

Results
Expert review No more findings on 7c68860
Tests No UI or device tests affected
Review threads 1 resolved

@kubaflo
kubaflo merged commit 21244b4 into net11 Dec 2, 2026
13 of 15 checks passed
@kubaflo
kubaflo deleted the simonrozsival-unit-test-hang-dumps branch December 2, 2026 12:40
kubaflo added a commit that referenced this pull request Dec 3, 2026
<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `7eaf806f7513810dcbd94ca03a1500a5ee4302f4`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 9.5/10 | ↑ [PR CI
1706633](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706633)
completed with all 33 jobs green, including all four TestUtils runner
and TRX validation pairs.<br>↑ The local suite also runs without the
opt-in; device-host invocation, test selection and pipeline
configuration are unchanged. |
| Diagnosis confidence | 10/10 | ↑ The HangDump package was already
restored, but the custom entry point did not register its provider;
removing only the registration reproduces exit 5, and restoring it
produces a valid TRX. |
| Evidence fit | 10/10 | ↑ The local baseline matched all four
Windows/macOS CI failures, and the same four configurations now execute
tests and validate their TRX with the original HangDump options. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

<!-- Enter description of the fix in this section -->

`TestUtils.UnitTests` exits before running any tests on Windows and
macOS Debug/Release in [net11 maui-pr
1706373](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706373),
with an invalid-arguments handshake failure (exit 5). #41038 passes
`--hangdump` and restores the HangDump package, but this project
supplies its own MTP entry point, so referencing the package doesn't
register its provider.

Register HangDump in the custom host only when `TestUtils.UnitTests`
builds with `EnableUnitTestHangDump=true`. Leave the diagnostic flags,
ordinary test runs, and device test hosts unchanged.

**Validation:** Ran on macOS arm64 with the repository .NET 11 SDK:

```sh
./.dotnet/dotnet test --project src/TestUtils/tests/TestUtils.UnitTests/TestUtils.UnitTests.csproj --configuration Debug --report-trx --hangdump --hangdump-timeout 10m --hangdump-type Mini -p:_SkipUpdateBuildNumber=true -p:EnableUnitTestHangDump=true --results-directory <results-dir>
```

| Run | Result |
| --- | --- |
| Unchanged net11 with the CI flags | Exit 5, handshake failure, no
tests ran |
| Unchanged net11 without the three HangDump flags, package still
enabled | 61 passed; 1 Windows-only test skipped |
| Fixed Debug with CI flags | 61 passed; 1 skipped; MTP TRX produced |
| Only the registration removed | Exit 5, handshake failure, no tests
ran |
| Registration restored, Debug and Release with CI flags | Each: 61
passed; 1 skipped; MTP TRX produced |
| Fixed Debug without the HangDump flags or opt-in | 61 passed; 1
skipped |

[maui-pr
1706633](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1706633)
completed successfully, with 33 succeeded timeline jobs. All four
targeted runner/validator pairs succeeded. Raw log pairs: macOS Debug
259/260 and Release 240/241 (61 passed, 1 skipped each); Windows Debug
333/334 and Release 367/368 (62 passed each).

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

No separate issue. Fixes the `TestUtils.UnitTests` handshake regression
in #41038.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Dec 3, 2026
… initializers (#41206)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `f55e53f8cb45bc70f5529273116a30be6308c945`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 9/10 | ↑ Fresh-process concurrency harness: fix
0/200 hangs, restored 0/30.<br>↑ Core.UnitTests Release 1138/1138 x3;
Controls.Core.UnitTests 6908 passed, 0 failed.<br>↓ CI on this PR not
yet observed. |
| Diagnosis confidence | 9.5/10 | ↑ dotnet-stack of a hung process shows
Label..cctor holding the helper lock waiting on VisualElement, while
VisualElement..cctor -> Element..cctor waits on the helper lock.<br>↑
Baseline 94/100 hung, reverted 29/30 hung. |
| Evidence fit | 8.5/10 | ↑ CI hangs show exactly the first-use Controls
tests (Label, ContentView, Button, DatePicker, Grid, mapper tests) all
blocked at startup.<br>↓ CI createdump failed, so no CI-side stack
confirms the identical cycle. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

**Symptom:** `maui-pr` on `candidate/11.0.1xx-sr3` intermittently fails
"macOS unit tests (Release)". In about half of the runs,
`Core.UnitTests` stalls with 11 tests blocked from startup until the
hangdump timeout (exit 7). Examples: builds 1706437, 1706493, 1707019,
1707055, 1707205 and PR build 1707259. These hangs show up as failures
because of the hang-dump infra from #41038.

**Root cause:** `RemappingHelper` held a single global lock while
running each Controls remap. #40930 changed `static Label()` to remap
through the helper. Label's remap calls `VisualElement.RemapIfNeeded()`,
which requires VisualElement's type initializer. With concurrent first
use:
- Thread A: `Label..cctor` → takes the helper lock → waits for
`VisualElement..cctor`
- Thread B: `VisualElement..cctor` (static brush field) →
`Element..cctor` → `Element.RemapIfNeeded` → waits for the helper lock

Neither thread can proceed, and the runtime does not detect a cycle that
mixes a monitor with type-init locks. The `dotnet-stack` capture of a
hung repro process shows exactly these two frames.

**Fix:** keep the run-once state in a short global lock, but run each
remap under a **per-type** lock. Same-type callers still wait for
completion. Reentrancy on the same thread still returns immediately. A
remap that throws is still not retried. Remaps of different types no
longer block each other, and the type dependency chain (Label →
VisualElement → Element) is acyclic.

`main` removed this helper in a larger lazy-remap redesign
(#40725/#40728), which is not appropriate for this candidate.

### Validation

A fresh-process harness against the built assemblies creates `Label`,
`ContentView`, `Button`, `BoxView`, `Grid` and `DatePicker` on 6
barrier-synchronized threads, with an 8 s join:

| Tree | Hung |
|---|---|
| Baseline e69e972 | 94/100 |
| Fix | 0/200 |
| Fix reverted | 29/30 |
| Restored | 0/30 |

- `dotnet test --project src/Core/tests/UnitTests/Core.UnitTests.csproj
-c Release`: 1138/1138 passed, 3 runs.
- `dotnet test --project
src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -c
Release`: 6908 passed, 0 failed (30 skipped). This includes
`LabelMapperCustomizationTests` from #40930.

### Issues Fixed

Fixes the intermittent macOS Release Core.UnitTests hang on
`candidate/11.0.1xx-sr3`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Dec 4, 2026
…41224)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `946bedc34f141ef215926b962ba240a7bf31d75e`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 9.5/10 | ↑ Exact cherry-pick of net11 #41148,
whose PR CI passed all four TestUtils runner/validator pairs.<br>↑ Local
sr3 run with CI's exact flags produces a TRX (61 passed, 1 skipped, 0
failed).<br>↓ sr3 maui-pr CI on this head is still pending. |
| Diagnosis confidence | 10/10 | ↑ Causal sequence on sr3 2253c0b:
baseline exit 5, fix exit 0, fix reverted exit 5, restored exit 0. |
| Evidence fit | 10/10 | ↑ Matches the sr3 maui-pr 1707534 failure
(`--hangdump ... -p:EnableUnitTestHangDump=true` then "exit code: 5. The
command-line arguments are invalid") on Windows and macOS. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Cherry-pick (`-x`) of net11 #41148 onto `candidate/11.0.1xx-sr3`.

`TestUtils.UnitTests` exits before running any tests in sr3 [maui-pr
1707534](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1707534)
on Windows and macOS. MTP reports exit 5, "command-line arguments are
invalid".

The cause: #41038 passes `--hangdump` and restores the HangDump package,
but this project supplies its own MTP entry point
(`HeadlessTestRunner`). That entry point never registered the HangDump
provider, so MTP rejected the flag. The fix registers
`AddHangDumpProvider()` when `EnableUnitTestHangDump=true`, using the
`ENABLE_UNIT_TEST_HANG_DUMP` define.

### Validation

Ran locally on sr3 `2253c0bf`, with the same flags CI uses:

`dotnet test --project
src/TestUtils/tests/TestUtils.UnitTests/TestUtils.UnitTests.csproj
--configuration Debug --report-trx --hangdump --hangdump-timeout 10m
--hangdump-type Mini --results-directory <dir>
-p:_SkipUpdateBuildNumber=true -p:EnableUnitTestHangDump=true`

| State | Exit | TRX |
|---|---|---|
| Baseline (sr3) | 5 | none |
| Fix | 0 | 62 total, 61 passed, 1 skipped (Windows-only) |
| Fix reverted | 5 | none |
| Restored | 0 | 62 total, 61 passed, 1 skipped (Windows-only) |

### Issues Fixed

N/A. This is a candidate CI fix, a port of #41148.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s/autopilot-waiting-for-maintainer-review MAUI Autopilot finished: expert review clean and tests passed; waiting for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants