Repository navigation
[net11] Recover lost Android emulator before UI test retry - #40273
Conversation
When the CI emulator disappears mid-run (logcat exits 255, adb reports device not found), the UI test retry ran every remaining fixture against the missing device. Each fixture waited ~3.7 minutes for an Appium session, so API 30 jobs hit the 240-minute job timeout and were cancelled. Add an optional beforeRetry hook to RunUITestsWithRetry. On Android it checks sys.boot_completed and, if the emulator was started by the script and is gone, restarts it and reinstalls the app before the retry; if it cannot be recovered, it fails immediately with the attempt-1 results. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40273Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40273" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 1 finding
Reviewed commit ee1eff9.
Source assessment incomplete (5/6 dimensions); finding count is partial.
See inline comments for details.
| { | ||
| EnsureDirectoryExists(retryDirectory); | ||
| // A retry against a lost device spends minutes per fixture waiting for a session; recover or fail fast. | ||
| beforeRetry?.Invoke(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No committed regression test exercises recovery through this retry loop. The reported temporary target calls EnsureDeviceForUITestRetry directly, so it cannot detect removal of this invocation: after attempt 1 loses the emulator, attempt 2 would again run against the missing device and incur the original per-fixture session waits. Add a deterministic runner/recovery harness that fails attempt 1 with a lost device and asserts restart plus reinstall precede attempt 2; cover recovery throwing (no second test invocation, first-attempt reports retained) and the healthy-device negative case (no restart or reinstall). The existing PowerShell retry tests exercise a different runner, not this Cake callback.
There was a problem hiding this comment.
Not adding a committed harness here. This PR only changes CI device-orchestration Cake scripts (eng/devices), and this repo's practice for pipeline/CI scripts is to validate with syntax checks plus real CI rather than a committed test harness.
Validation so far:
- Cake
--dryruncompiles for android, catalyst and windows. iOS shows the same environmental teardown error with and without this change. - In a local API 30 harness, the healthy-device check was a no-op (1.1 s). After
adb emu kill, the hook detected the loss, restarted the emulator, reinstalled the app, and XHarness exited 0 (76 s total). - In CI run 1682445, 26 Android API 30 jobs completed green in 13–37 min. Earlier
net11runs 1680926 and 1680462 were cancelled at the 240-min limit.
Gap: no emulator was lost in 1682445, so the CI recovery path itself is still unexercised. Leaving this thread open for a maintainer to decide.
Auto-replied by the GitHub Copilot app
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
There was a problem hiding this comment.
Expert Review — 1 finding
Reviewed commit ee1eff9.
Source assessment incomplete (5/6 dimensions); finding count is partial.
See inline comments for details.
| { | ||
| EnsureDirectoryExists(retryDirectory); | ||
| // A retry against a lost device spends minutes per fixture waiting for a session; recover or fail fast. | ||
| beforeRetry?.Invoke(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No committed regression test exercises recovery through this retry loop. The temporary target calls EnsureDeviceForUITestRetry directly, so removing this invocation would leave that validation unchanged while attempt 2 again runs against a missing emulator, repeating the original per-fixture session waits. Add a deterministic orchestration harness asserting that restart and reinstall precede attempt 2 after device loss; also cover recovery throwing (no second test invocation and first-attempt reports retained) and a healthy device (no restart or reinstall). The existing PowerShell retry tests exercise a different runner and cannot detect missing Cake callback wiring.
There was a problem hiding this comment.
This repeats the request in the earlier thread (#40273 (comment)). The answer is the same: I'm not adding a committed Cake orchestration test harness. This is CI pipeline code, and by maintainer policy pipeline changes are validated with configuration checks and real CI runs, not with dedicated tests.
On the callback wiring specifically:
- The local validation drove the real path. The emulator on a pinned serial was killed, the hook restarted it, reinstalled the app, and XHarness then exited 0.
- maui-pr-uitests run 1682445 is exercising this PR now. Its Android API 30 jobs will show whether attempt 2 runs against a recovered device, a lost device, or neither, so it covers the wiring regression you describe. I'll report those raw-log results here once the run completes.
Auto-replied by the GitHub Copilot app
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
) <!-- 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 Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. ### Issues Fixed Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Follow-up CI evidence from maui-pr-uitests 1683189: all 31 API 30 jobs succeeded, taking 12.65–43.50 minutes, with no 240-minute timeout. Raw logs and complete published result sets were checked, not just job status. The recovery path was exercised three times:
CollectionView3 initially had 61 passed/56 failed after losing the emulator. The hook logged The Android emulator is no longer available, killed the old process, restarted the emulator, reinstalled the app (13:06:30Z), and started retry tests at 13:06:44Z. The whole job finished successfully in 43.5 minutes. The two before-attempt-1 recoveries show the same restart/reinstall-before-tests ordering. Scope: this run tested merge 24ac5af (head 33b8d28 into ea39223). Its three recovery/retry Cake files exactly match current net11 d0547a0, but its full dependency tree does not. This confirms both recovery wiring paths in CI; it does not identify why the emulators exited or certify the entire current net11 tip. Separate net11 run 1683205 remains in progress. |
…#40300) <!-- 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 Follow-up to #40273, which recovers a lost Android emulator **between** UI test attempts. That recovery cannot help when the emulator dies **during** an attempt: every remaining fixture then calls `AppiumServerContext.CreateUIClientContext`, which tries to create a session 11 times (`retries++ < 10`, about 20s each because UiAutomator2 waits 20s for a device). Each fixture fails only after **3m40s**. Evidence from `maui-pr-uitests` run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664) (PR #40273), job "Controls (API 30) Label": - The emulator vanished about 3 minutes into attempt 1. - All 126 Label tests then failed in `OneTimeSetUp` with `Could not find a connected Android device in 20000ms`, each after 3m40s. - The test step took **195 minutes**; normally it takes 16–23 minutes. - Only after that did the between-attempt recovery restart the emulator. `net11` run [1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205) showed the same job still running after 115+ minutes. The candidate (#40116) and `main` have identical copies of this file, so no existing fix covers it. **Change:** after one fixture exhausts all retries, later fixtures in the same test process get a single attempt. A successful session restores full retries. - The first failure still gets the full retry budget, so transient Appium or device hiccups keep the current tolerance. - CI retries start a new `dotnet test` process, so each attempt starts with full retries, and the emulator recovery from #40273 still runs before it. - No test is skipped, and no tolerance or baseline changes. ### Validation Ran a local console harness that references `UITest.Core` and `UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and calls `CreateUIClientContext` with an Android config and no connected device. This simulates fixtures after the emulator is lost. | Build | Fixture 1 | Fixture 2 | Fixture 3 | | --- | --- | --- | --- | | `net11` (baseline, d0547a0) | 221s | 221s | — | | This PR | 221s | 20s | 20s | For a 126-fixture category, the time to fail after losing the emulator drops from about 7.7h (capped by the job timeout) to about 45 min. The same error message is still reported for every test. ### Issues Fixed Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt emulator loss (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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 Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. ### Issues Fixed Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…dotnet#40300) <!-- 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 Follow-up to dotnet#40273, which recovers a lost Android emulator **between** UI test attempts. That recovery cannot help when the emulator dies **during** an attempt: every remaining fixture then calls `AppiumServerContext.CreateUIClientContext`, which tries to create a session 11 times (`retries++ < 10`, about 20s each because UiAutomator2 waits 20s for a device). Each fixture fails only after **3m40s**. Evidence from `maui-pr-uitests` run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664) (PR dotnet#40273), job "Controls (API 30) Label": - The emulator vanished about 3 minutes into attempt 1. - All 126 Label tests then failed in `OneTimeSetUp` with `Could not find a connected Android device in 20000ms`, each after 3m40s. - The test step took **195 minutes**; normally it takes 16–23 minutes. - Only after that did the between-attempt recovery restart the emulator. `net11` run [1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205) showed the same job still running after 115+ minutes. The candidate (dotnet#40116) and `main` have identical copies of this file, so no existing fix covers it. **Change:** after one fixture exhausts all retries, later fixtures in the same test process get a single attempt. A successful session restores full retries. - The first failure still gets the full retry budget, so transient Appium or device hiccups keep the current tolerance. - CI retries start a new `dotnet test` process, so each attempt starts with full retries, and the emulator recovery from dotnet#40273 still runs before it. - No test is skipped, and no tolerance or baseline changes. ### Validation Ran a local console harness that references `UITest.Core` and `UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and calls `CreateUIClientContext` with an Android config and no connected device. This simulates fixtures after the emulator is lost. | Build | Fixture 1 | Fixture 2 | Fixture 3 | | --- | --- | --- | --- | | `net11` (baseline, d0547a0) | 221s | 221s | — | | This PR | 221s | 20s | 20s | For a 126-fixture category, the time to fail after losing the emulator drops from about 7.7h (capped by the job timeout) to about 45 min. The same error message is still reported for every test. ### Issues Fixed Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt emulator loss (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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 Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. ### Issues Fixed Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…dotnet#40300) <!-- 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 Follow-up to dotnet#40273, which recovers a lost Android emulator **between** UI test attempts. That recovery cannot help when the emulator dies **during** an attempt: every remaining fixture then calls `AppiumServerContext.CreateUIClientContext`, which tries to create a session 11 times (`retries++ < 10`, about 20s each because UiAutomator2 waits 20s for a device). Each fixture fails only after **3m40s**. Evidence from `maui-pr-uitests` run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664) (PR dotnet#40273), job "Controls (API 30) Label": - The emulator vanished about 3 minutes into attempt 1. - All 126 Label tests then failed in `OneTimeSetUp` with `Could not find a connected Android device in 20000ms`, each after 3m40s. - The test step took **195 minutes**; normally it takes 16–23 minutes. - Only after that did the between-attempt recovery restart the emulator. `net11` run [1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205) showed the same job still running after 115+ minutes. The candidate (dotnet#40116) and `main` have identical copies of this file, so no existing fix covers it. **Change:** after one fixture exhausts all retries, later fixtures in the same test process get a single attempt. A successful session restores full retries. - The first failure still gets the full retry budget, so transient Appium or device hiccups keep the current tolerance. - CI retries start a new `dotnet test` process, so each attempt starts with full retries, and the emulator recovery from dotnet#40273 still runs before it. - No test is skipped, and no tolerance or baseline changes. ### Validation Ran a local console harness that references `UITest.Core` and `UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and calls `CreateUIClientContext` with an Android config and no connected device. This simulates fixtures after the emulator is lost. | Build | Fixture 1 | Fixture 2 | Fixture 3 | | --- | --- | --- | --- | | `net11` (baseline, d0547a0) | 221s | 221s | — | | This PR | 221s | 20s | 20s | For a 126-fixture category, the time to fail after losing the emulator drops from about 7.7h (capped by the job timeout) to about 45 min. The same error message is still reported for every test. ### Issues Fixed Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt emulator loss (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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 Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. ### Issues Fixed Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…dotnet#40300) <!-- 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 Follow-up to dotnet#40273, which recovers a lost Android emulator **between** UI test attempts. That recovery cannot help when the emulator dies **during** an attempt: every remaining fixture then calls `AppiumServerContext.CreateUIClientContext`, which tries to create a session 11 times (`retries++ < 10`, about 20s each because UiAutomator2 waits 20s for a device). Each fixture fails only after **3m40s**. Evidence from `maui-pr-uitests` run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664) (PR dotnet#40273), job "Controls (API 30) Label": - The emulator vanished about 3 minutes into attempt 1. - All 126 Label tests then failed in `OneTimeSetUp` with `Could not find a connected Android device in 20000ms`, each after 3m40s. - The test step took **195 minutes**; normally it takes 16–23 minutes. - Only after that did the between-attempt recovery restart the emulator. `net11` run [1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205) showed the same job still running after 115+ minutes. The candidate (dotnet#40116) and `main` have identical copies of this file, so no existing fix covers it. **Change:** after one fixture exhausts all retries, later fixtures in the same test process get a single attempt. A successful session restores full retries. - The first failure still gets the full retry budget, so transient Appium or device hiccups keep the current tolerance. - CI retries start a new `dotnet test` process, so each attempt starts with full retries, and the emulator recovery from dotnet#40273 still runs before it. - No test is skipped, and no tolerance or baseline changes. ### Validation Ran a local console harness that references `UITest.Core` and `UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and calls `CreateUIClientContext` with an Android config and no connected device. This simulates fixtures after the emulator is lost. | Build | Fixture 1 | Fixture 2 | Fixture 3 | | --- | --- | --- | --- | | `net11` (baseline, d0547a0) | 221s | 221s | — | | This PR | 221s | 20s | 20s | For a 126-fixture category, the time to fail after losing the emulator drops from about 7.7h (capped by the job timeout) to about 45 min. The same error message is still reported for every test. ### Issues Fixed Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt emulator loss (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…up (#40381) <!-- 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 Android UI test jobs can lose all tests when the emulator wedges before it finishes booting. `uitest-prepare` already retries five times (`RunUITestSetupWithRetry`), but each retry reuses the same emulator. Every attempt waits another 600 s on that wedged instance. The restart added in #40273 runs only before test attempts, not before setup retries. Examples: - net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator shows `offline` and then "no devices" for about an hour. All 5 setup attempts wait on the same process, which stays alive until final cleanup. No tests run. - Candidate UI build 1686311 CV2 (log 3682) has the same five attempts with no relaunch. There the device was stuck `unauthorized`. Change (`eng/devices/android.cake`): - I extracted the existing #40273 restart logic into `RestartEmulatorIfNotBooted(nextStep)`. - `uitest-prepare` calls it before setup attempts 2–5. - It restarts only an emulator this script launched, and only when `sys.boot_completed` is not set. Booted devices and externally provided devices are untouched. - `EnsureDeviceForUITestAttempt` keeps its behavior. The root cause of the emulator wedge is unknown. This change only lets the retries recover from it. ### Validation Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled (`AGENT_NAME` set) and an isolated ADB server and home directory. To simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s after launch. This reproduces the CI shape: adb shows `device offline` and the boot wait fails at 600 s. - **Baseline (net11 `android.cake`):** attempt 1 failed with "The emulator did not finish booting in time". Attempt 2 waited again on the same stopped PID, with no relaunch. **Red.** - **This PR:** attempt 1 failed the same way. Then "The Android emulator is not booted; restarting it before retrying UI test setup." The emulator was killed and relaunched, booted in 15 s, and the APK installed. Exit 0. **Green.** - **Control (no wedge):** normal boot, no restart. Exit 0. The `unauthorized` mode (log 3682) was not reproduced locally. A relaunch is expected to help it as well, but that is not validated. ### Issues Fixed Fixes net11 Android UI test jobs lost to an emulator that wedges during boot (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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. --> | 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. Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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. --> | 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. Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…up (dotnet#40381) <!-- 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 Android UI test jobs can lose all tests when the emulator wedges before it finishes booting. `uitest-prepare` already retries five times (`RunUITestSetupWithRetry`), but each retry reuses the same emulator. Every attempt waits another 600 s on that wedged instance. The restart added in dotnet#40273 runs only before test attempts, not before setup retries. Examples: - net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator shows `offline` and then "no devices" for about an hour. All 5 setup attempts wait on the same process, which stays alive until final cleanup. No tests run. - Candidate UI build 1686311 CV2 (log 3682) has the same five attempts with no relaunch. There the device was stuck `unauthorized`. Change (`eng/devices/android.cake`): - I extracted the existing dotnet#40273 restart logic into `RestartEmulatorIfNotBooted(nextStep)`. - `uitest-prepare` calls it before setup attempts 2–5. - It restarts only an emulator this script launched, and only when `sys.boot_completed` is not set. Booted devices and externally provided devices are untouched. - `EnsureDeviceForUITestAttempt` keeps its behavior. The root cause of the emulator wedge is unknown. This change only lets the retries recover from it. ### Validation Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled (`AGENT_NAME` set) and an isolated ADB server and home directory. To simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s after launch. This reproduces the CI shape: adb shows `device offline` and the boot wait fails at 600 s. - **Baseline (net11 `android.cake`):** attempt 1 failed with "The emulator did not finish booting in time". Attempt 2 waited again on the same stopped PID, with no relaunch. **Red.** - **This PR:** attempt 1 failed the same way. Then "The Android emulator is not booted; restarting it before retrying UI test setup." The emulator was killed and relaunched, booted in 15 s, and the APK installed. Exit 0. **Green.** - **Control (no wedge):** normal boot, no restart. Exit 0. The `unauthorized` mode (log 3682) was not reproduced locally. A relaunch is expected to help it as well, but that is not validated. ### Issues Fixed Fixes net11 Android UI test jobs lost to an emulator that wedges during boot (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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. --> | 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. Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…up (dotnet#40381) <!-- 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 Android UI test jobs can lose all tests when the emulator wedges before it finishes booting. `uitest-prepare` already retries five times (`RunUITestSetupWithRetry`), but each retry reuses the same emulator. Every attempt waits another 600 s on that wedged instance. The restart added in dotnet#40273 runs only before test attempts, not before setup retries. Examples: - net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator shows `offline` and then "no devices" for about an hour. All 5 setup attempts wait on the same process, which stays alive until final cleanup. No tests run. - Candidate UI build 1686311 CV2 (log 3682) has the same five attempts with no relaunch. There the device was stuck `unauthorized`. Change (`eng/devices/android.cake`): - I extracted the existing dotnet#40273 restart logic into `RestartEmulatorIfNotBooted(nextStep)`. - `uitest-prepare` calls it before setup attempts 2–5. - It restarts only an emulator this script launched, and only when `sys.boot_completed` is not set. Booted devices and externally provided devices are untouched. - `EnsureDeviceForUITestAttempt` keeps its behavior. The root cause of the emulator wedge is unknown. This change only lets the retries recover from it. ### Validation Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled (`AGENT_NAME` set) and an isolated ADB server and home directory. To simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s after launch. This reproduces the CI shape: adb shows `device offline` and the boot wait fails at 600 s. - **Baseline (net11 `android.cake`):** attempt 1 failed with "The emulator did not finish booting in time". Attempt 2 waited again on the same stopped PID, with no relaunch. **Red.** - **This PR:** attempt 1 failed the same way. Then "The Android emulator is not booted; restarting it before retrying UI test setup." The emulator was killed and relaunched, booted in 15 s, and the APK installed. Exit 0. **Green.** - **Control (no wedge):** normal boot, no restart. Exit 0. The `unauthorized` mode (log 3682) was not reproduced locally. A relaunch is expected to help it as well, but that is not validated. ### Issues Fixed Fixes net11 Android UI test jobs lost to an emulator that wedges during boot (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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. --> | 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. Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
) <!-- 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. --> | 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. Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…up (dotnet#40381) <!-- 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 Android UI test jobs can lose all tests when the emulator wedges before it finishes booting. `uitest-prepare` already retries five times (`RunUITestSetupWithRetry`), but each retry reuses the same emulator. Every attempt waits another 600 s on that wedged instance. The restart added in dotnet#40273 runs only before test attempts, not before setup retries. Examples: - net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator shows `offline` and then "no devices" for about an hour. All 5 setup attempts wait on the same process, which stays alive until final cleanup. No tests run. - Candidate UI build 1686311 CV2 (log 3682) has the same five attempts with no relaunch. There the device was stuck `unauthorized`. Change (`eng/devices/android.cake`): - I extracted the existing dotnet#40273 restart logic into `RestartEmulatorIfNotBooted(nextStep)`. - `uitest-prepare` calls it before setup attempts 2–5. - It restarts only an emulator this script launched, and only when `sys.boot_completed` is not set. Booted devices and externally provided devices are untouched. - `EnsureDeviceForUITestAttempt` keeps its behavior. The root cause of the emulator wedge is unknown. This change only lets the retries recover from it. ### Validation Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled (`AGENT_NAME` set) and an isolated ADB server and home directory. To simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s after launch. This reproduces the CI shape: adb shows `device offline` and the boot wait fails at 600 s. - **Baseline (net11 `android.cake`):** attempt 1 failed with "The emulator did not finish booting in time". Attempt 2 waited again on the same stopped PID, with no relaunch. **Red.** - **This PR:** attempt 1 failed the same way. Then "The Android emulator is not booted; restarting it before retrying UI test setup." The emulator was killed and relaunched, booted in 15 s, and the APK installed. Exit 0. **Green.** - **Control (no wedge):** normal boot, no restart. Exit 0. The `unauthorized` mode (log 3682) was not reproduced locally. A relaunch is expected to help it as well, but that is not validated. ### Issues Fixed Fixes net11 Android UI test jobs lost to an emulator that wedges during boot (no tracking issue). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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
mainnet11, for reviewFor .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
Most of the recent
net11maui-pr-uitestsred comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions.What happens (raw logs of build 1680926 and 1680462, e.g. API 30 Navigation and API 30 CollectionView3):
[Logcat] Logcat terminated with code 255appears and adb reportsdevice 'emulator-5554' not found. The emulator is gone.RunUITestsWithRetrystarts UI test attempt 2 against the still-missing device. Every fixture now waits about 3.7 minutes inAppiumServerContext.CreateUIClientContext: 11 tries × Appium's 20-second "Could not find a connected Android device".The same tests pass on
candidate/11.0.1xx-sr2, and none ofeng/devices,UITest.AppiumorUITest.NUnitdiffers betweennet11, the candidate andmain. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport.Fix
RunUITestsWithRetrygets an optionalbeforeAttempthook that runs before every attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged.sys.boot_completed:getprop).HandleVirtualDevicepath, and reinstalls the app withExecutePrepareUITestsbefore the attempt.AdbEmuKillfails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s.EmulatorKillTimeoutSeconds) until the old process has confirmed exited. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD.uitest-retry.cake: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child withsite="Parent". If OneTimeTearDown also throws, the fixture site becomesTearDowninstead ofSetUp. Ignored tests then come back from a green retry as Skipped/Ignored: either a static[Ignore]with the same reason, or a runtimeAssert.Ignorewithrunstate="Runnable". The merge accepted only theSetUp+static-reason shape, so the job failed even though the retry was green.SetUp, or the child's message starts withOneTimeSetUp:). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted.Validation
dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryruncompiles. iOS has the same pre-existing local teardown error with and without this change.Local end-to-end check on an API 30 arm64 emulator (adb pinned to
emulator-5554): a temporary target ran the realconnectToDeviceanduitest-prepare(installed the app), then calledEnsureDeviceForUITestAttemptas at the attempt-1 call site.adb emu killafter install (the 1682445 mode)boot_completed→ null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwardsboot_completed= 1 andpm pathshowed the appConfirmed-exit fault injection (local, API 30):
CI proof of recovery: in this PR's run 1682664, Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and attempt 2 passed 124 tests with 2 skipped in 14 minutes.
Retry merge: that job was still marked failed because two never-run ignored tests stayed Failed:
Issue488TestsLongTextRotation(static[Ignore], fixture siteTearDown) andLabelUITests.IsEnabled(runtimeAssert.Ignore). The real TRX and NUnit XML from both attempts were replayed offline throughUITestRetry.MergeResults:IsEnabled,Issue488TestsLongTextRotation)IsEnabledactually failsIsEnabledactually ran (site not Parent)OneTimeSetUp:evidenceThe replay harness was local only; no test was committed, per policy for CI scripts.
Final validation is this PR's own
maui-pr-uitestsrun.Issues Fixed
Fixes Android API 30
maui-pr-uitestsjobs onnet11hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored.