Skip to content

[tests] Fail fast when the emulator package manager service is wedged#11966

Merged
jonathanpeppers merged 1 commit into
mainfrom
dev/simonrozsival/emulator-test-robustness
Jul 6, 2026
Merged

[tests] Fail fast when the emulator package manager service is wedged#11966
jonathanpeppers merged 1 commit into
mainfrom
dev/simonrozsival/emulator-test-robustness

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Problem

Device integration tests (DeviceTest) gate on adb shell echo OK in the shared [SetUp] before running. That check succeeds even when the emulator's system_server / package manager service has crashed or wedged. As a result the health check passes, the test proceeds to build and install an app, and then fails deep inside the build with a cryptic error:

[BT:1.18.3] error: Unexpected output of 'pm list features' command:
    'cmd: Failure calling service package: Broken pipe (32)'
error XABAS0000: com.android.tools.build.bundletool...AdbOutputParseException
   at ...DeviceFeaturesParser.parse
   at ...DeviceAnalyzer.getDeviceSpec

Because these tests run a combined /t:Build,Install target, an emulator/service failure surfaces as a misleading FailedBuildException: "Build failure" — reported as N unrelated per-test failures long after the emulator actually died, instead of a single clear "emulator unusable" signal up front.

Observed in the wild: a single macOS emulator lane failed 8 diverse tests (BundleTool, Debugging, InstallAndRun, StoreKey) while every other build/test lane stayed green — the classic signature of a wedged package service, not a product regression.

Fix

Probe the package manager service — the same pm list features binder path that bundletool build-apks --connected-device and adb install rely on — in the shared SetUp:

  • IsPackageManagerResponsive(out diagnostic) — retries a few times so a momentary hiccup doesn't trigger an unnecessary emulator restart.
  • AssertPackageManagerResponsive() — if the service is wedged, restart the emulator once; if it's still broken, Assert.Inconclusive with a clear "package manager service is unresponsive (system_server likely crashed)" message.

This surfaces the failure before building/installing the app, once, with a real reason — and marks it inconclusive (an infrastructure problem) rather than turning an emulator crash into product-test failures, consistent with the existing RestartDevice transient-failure handling.

Device integration tests only gate on "adb shell echo OK" before running.
That succeeds even when the emulator's system_server / package manager
service has crashed, so the health check passes, the test proceeds to build
and install an app, and then fails deep inside the build with a cryptic
bundletool "Failure calling service package: Broken pipe (32)" (XABAS0000) -
reported as N unrelated per-test failures long after the emulator died.

Probe the package manager service (the same "pm list features" path that
bundletool "build-apks --connected-device" and "adb install" use) in the
shared SetUp. When it is wedged, restart the emulator once; if it is still
broken, mark the run inconclusive with a clear "package manager service is
unresponsive" message so an emulator failure is surfaced immediately and is
not mistaken for a product regression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 3, 2026 07:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a stronger emulator health check to the shared device-test SetUp so infrastructure failures (wedged system_server / package manager binder) are detected early and reported as inconclusive rather than cascading into many misleading build/install test failures.

Changes:

  • Introduces IsPackageManagerResponsive(out diagnostic) which probes adb shell pm list features with retries to detect a broken package service.
  • Adds AssertPackageManagerResponsive() to restart the emulator once and mark the run inconclusive if the service remains unresponsive.
  • Calls the new assertion from the shared [SetUp] to fail fast before build/install work begins.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs Adds package-manager responsiveness probing and a fail-fast setup check to restart/skip on emulator service wedges.

Copilot's findings

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

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jul 3, 2026
@jonathanpeppers
jonathanpeppers merged commit 1eb38a4 into main Jul 6, 2026
43 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/emulator-test-robustness branch July 6, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-tests ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants