Skip to content

Speed Up the Android Camera and MediaControls Device Tests, and Fix a Flaky Android 10 Test - #3462

Merged
TheCodeTraveler merged 8 commits into
mainfrom
Speed-Up-the-Slowest-Device-Test-Classes
Nov 30, 2026
Merged

TheCodeTraveler merged 8 commits into
mainfrom
Speed-Up-the-Slowest-Device-Test-Classes

Conversation

@TheCodeTraveler

@TheCodeTraveler TheCodeTraveler commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description of Change

Speeds up the Android camera and MediaControls device tests by about 30 s per Android CI job: a full local API 36 run went from 1,190 s to 1,157 s. It also fixes a flaky Android 10 MediaElement device test. No library code changes. No test, row, assertion or timeout is removed or loosened.

Details for reviewers: what changed, measurements, what was kept

Where the time goes (CI API 33, run 46237553696): each row of these classes spends 0.6-1.0 s in teardown, outside its reported time. Most of it is Android work the tests must wait for:

  • Camera: cameraserver takes 0.4-0.5 s to close each camera on API 33 and later.
  • MediaControls: the 1.5 s pause that keeps Android from dropping notification updates.
  • FileSaver, FolderPicker, ActivityResultManager: Android redraws the stopped test-runner activity after each fake picker closes. Not changed here (see below).

Changes:

  • CameraAndroidTestBase: checks for the preview stream and for the first recorded sample every 20 ms instead of 100 ms. AssertEventually counts attempts, so its wall-clock timeout can only get longer. The MP4-header check stays at 100 ms, because a check during MediaMuxer.start can see a partly written header.
  • CameraClosedCheck.GetDelayBeforeTheNextCheck: WaitForClosedAsync now checks just after a settling camera's 600 ms window ends, as AssertClosedNowAsync already did, instead of every 100 ms. Same window, same verdict rule. New 3-row test: TheNextCheckWaitsForTheEndOfTheWindowOnlyWhileACameraIsSettling.
  • MediaElementAndroidTestBase: teardown skips its 1.5 s pause only when the test itself just ended with that pause, nothing was hosted after it, the service has stopped and no notification is showing. That is 3 rows; every other foreground-service row still pauses.

Measured (Release, local emulators: main 766489a once, this branch 3 times):

API 36 API 28
Camera classes -24.5 s (full run: -28.0 s) -18.2 s
MediaControlsService -4.7 s -4.3 s
Full run, xUnit time 1,190.5 s -> 1,155.7-1,157.5 s
  • On CI (API 28, 33 and 36), the waits this PR touches got shorter as planned: the closed-camera check from about 0.66 s to 0.61 s per row, the wait after the preview starts from 67-87 ms to 20-32 ms, and MediaControls teardown by 4.5 s. Whole-class times vary too much between CI runs to give one exact total.
  • Every run passed: 67 local runs, 0 failures. Every class has the same rows before and after, plus the 3 new ones. No notification was dropped in any run.

Left out on purpose:

  • Handing the fake picker over between FileSaver, FolderPicker and ActivityResultManager rows would save another 60-95 s on API 33. But ActivityResultManager, the code under test, would then see the next activity created before the previous one is destroyed at every row start, a state today's tests never produce.
  • The 600 ms closed-check window, the 1.5 s notification pause and every timeout stay as they are.

Flaky test fixed: MauiMediaElementAndroidTests.HidingTheViewWhileInFullscreenDoesNotChangeTheSystemBars(visibility: Invisible) failed once on API 29 in this PR's first CI run ("The system bars never stayed hidden."), and about once in 100 API 29 runs overall.

  • Cause: before Android 11, the system reports every system-bar change back to the app in order. When SystemUI is slow, the previous test's late "bars visible" report can arrive after this test hides the bars, and it undoes the hide. On CI, the "Viewing full screen" prompt's slow frames blocked the system UI thread for about 1.2 s. An Android race, not a MediaElement bug.
  • Fix (tests only): on API 29 and older, the helpers wait for SystemUI to catch up before they hide the bars. They set and clear the unused low-profile bit and wait for both reports; reports arrive in order, so every earlier one has arrived. Failure messages now include the system UI visibility and the window focus. The assertion, its 500 ms hold and its 5 s timeout are unchanged.
  • Proof on a local API 29 emulator, pausing SystemUI across the previous test's report: main failed 3 of 3 such runs with the CI error and passed the 6 runs where the pause missed it; this branch passed 6 of 6 such runs plus 3 normal runs. The MediaElement tests also pass on API 27, 28 and 36.

Linked Issues

  • None: a test-only speed-up of the device tests.

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal) (n/a: test-only)
  • Has tests (one new 3-row test for the new helper; everything else is test code)
  • Has samples (n/a: test-only)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Trim and NativeAOT safe: no new IL warnings, no new RequiresUnreferencedCode/RequiresDynamicCode/suppressions (see .github/instructions/trimming-aot.instructions.md)
  • Documentation created or updated (n/a: test-only)

Additional information

Tested on Android API 36 and API 28 emulators (Release). CI runs every platform.

🤖 Generated with Claude Code

TheCodeTraveler and others added 4 commits November 29, 2026 08:33
…t Teardown

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… They Prove

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheCodeTraveler
TheCodeTraveler marked this pull request as ready for review November 29, 2026 20:07
TheCodeTraveler and others added 4 commits November 29, 2026 13:56
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ndroid 10 and Older

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reword the comment and split the two low-profile steps into one named local function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheCodeTraveler TheCodeTraveler changed the title Speed Up the Android Camera and MediaControls Device Tests Speed Up the Android Camera and MediaControls Device Tests, and Fix a Flaky Android 10 Test Nov 30, 2026
@TheCodeTraveler
TheCodeTraveler merged commit d37e170 into main Nov 30, 2026
53 checks passed
@TheCodeTraveler
TheCodeTraveler deleted the Speed-Up-the-Slowest-Device-Test-Classes branch November 30, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant