Repository navigation
[net11] Fail fast on Appium session creation after the device is lost - #40300
Conversation
When the Android emulator dies mid attempt, every remaining fixture spent 11 x 20s retrying session creation (3m40s each), turning a 126-test category into a ~3h hang before the between-attempt emulator recovery could run. After one fixture exhausts its retries, later fixtures get a single attempt; a successful session restores full retries. 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 -- 40300Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40300" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/rebase |
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. |
| // Once a fixture exhausts every retry the device is usually gone (e.g. a crashed emulator). | ||
| // Give later fixtures a single attempt so the rest of the run fails in minutes instead of hours, | ||
| // leaving time for the CI retry to recover the device; a successful session restores full retries. | ||
| int maxRetries = _sessionRetriesExhausted ? 0 : MaxSessionRetries; |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No committed regression test exercises this cross-call retry state; the local console harness described in the PR is not included. Add deterministic infrastructure coverage using the same server context: exhausting 11 attempts must reduce subsequent calls to one attempt, a successful session must restore the full budget, and 10 transient failures followed by success must leave the next call's budget unchanged. Existing UI fixtures acquire their session during setup and do not assert these attempt counts, so they cannot detect the original repeated-delay behavior or a regression in the recovery/reset boundary.
There was a problem hiding this comment.
Not adding a committed test here. UITest.Appium has no unit-test project, and CreateUIClientContext builds real AppiumAndroidApp drivers directly. A deterministic attempt-count test would need a new test project plus a driver-factory seam in shared UI-test infrastructure. That is a larger refactor than this targeted CI-reliability fix.
Validation for this change:
- A local harness ran against a bogus Android serial. Before the fix, every call made 11 attempts; after it, the first call made 11 and later calls made 1.
- The raw CI evidence from runs 1682664 and 1683205 is linked in the description and comments.
The reset paths are a single assignment: a successful session clears the flag, and each new dotnet test process starts cleared. If maintainers want a seam and test project for UITest.Appium, I'd suggest that as a separate change.
Auto-replied by the GitHub Copilot app
|
More evidence from the
|
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 a5c5673.
Previously reported findings were not duplicated.
…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>
…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>
…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>
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
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-uitestsrun 1682664 (PR #40273), job "Controls (API 30) Label":OneTimeSetUpwithCould not find a connected Android device in 20000ms, each after 3m40s.net11run 1683205 showed the same job still running after 115+ minutes. The candidate (#40116) andmainhave 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.
dotnet testprocess, so each attempt starts with full retries, and the emulator recovery from [net11] Recover lost Android emulator before UI test retry #40273 still runs before it.Validation
Ran a local console harness that references
UITest.CoreandUITest.Appium, starts the real Appium server (uiautomator2 3.9.1), and callsCreateUIClientContextwith an Android config and no connected device. This simulates fixtures after the emulator is lost.net11(baseline, d0547a0)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-uitestsAndroid jobs after mid-attempt emulator loss (no tracking issue).