Skip to content

fix(visual): wait for rendered map content to settle in waitForMapRendering - #37

Open
dkhawk wants to merge 4 commits into
mainfrom
fix/visual-wait-for-map-rendering
Open

dkhawk wants to merge 4 commits into
mainfrom
fix/visual-wait-for-map-rendering

Conversation

@dkhawk

@dkhawk dkhawk commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes intermittent VisualMapSampleTest.verifyStoreLocatorMapRendering flakes on cold CI emulators where Gemini Vision saw a blank/unloaded Google Map surface.

Root Cause

BaseVisualTest.waitForMapRendering(timeoutSeconds) hardcoded a 3-second UI hierarchy wait and clamped its blind sleep to timeoutSeconds.coerceAtMost(5) without verifying that map tiles had actually drawn. On software-rendered CI emulators (swiftshader_indirect), Play Services Maps initialization and initial tile fetches can exceed 5 seconds.

Changes

  • Added MapRenderingReadiness (internal) to sample the inset interior of the map bounds, distinguishing rendered tiles/overlays from blank or loading-grid surfaces and verifying frame stabilization across consecutive polls.
  • Updated BaseVisualTest.waitForMapRendering(timeoutSeconds) to honor the full timeoutSeconds budget and return early as soon as map content renders and settles (no public API signature changes).
  • Updated VisualMapSampleTest to use the 30-second default waitForMapRendering().
  • Added unit tests in MapRenderingReadinessTest.

Verification

  • ./gradlew spotlessApply test lint spotlessCheck apiCheck docs:dokkaGenerate passed.

@dkhawk
dkhawk marked this pull request as ready for review November 24, 2026 22:55
@github-actions

Copy link
Copy Markdown

Coverage (unit tests)

No unit baseline recorded in coverage/history.csv yet, so this run only reports absolute numbers.

Module Line % Change Branch % Change
golden-testing 90.42% new 58.00% new
maps3d-robolectric-testing 71.65% new 50.94% new
robolectric-testing 84.25% new 51.87% new
visual-testing 66.34% new 40.75% new
TOTAL 80.31% new 48.55% new

Line and branch coverage from unit test reports. History is recorded in coverage/history.csv after each merge to main.

…dering

BaseVisualTest.waitForMapRendering previously hardcoded a 3-second UI wait and clamped its sleep to at most 5 seconds, causing VisualMapSampleTest to flake on cold CI emulators when map tiles had not finished loading.

Replace the blind sleep with pixel-based map-readiness and frame-stabilization polling that honors the full timeoutSeconds budget, returns early once rendered tiles settle, and updates VisualMapSampleTest to use the 30-second default timeout.
@dkhawk
dkhawk force-pushed the fix/visual-wait-for-map-rendering branch from d5fc37e to 08a85cf Compare November 24, 2026 23:47
@dkhawk
dkhawk requested review from a team and kikoso as code owners November 24, 2026 23:47
android-emulator-runner executes each line of `script` in its own `sh -c`,
so the multi-line if/fi block failed with "Syntax error: end of file
unexpected (expecting "fi")" after connectedAndroidTest had passed, and
`status` was never carried between lines.

Collapse the diagnostics into one line that keeps the Gradle exit status,
always prints the filtered logcat (BaseVisualTest settle/timeout messages,
Maps authorization errors) and only saves the full logcat on failure.
The Maps SDK logs the API key in plain text on authorization failures.
Secret masking covers the job log but not the uploaded
emulator-logcat.txt artifact, so redact AIza keys from both the filtered
and the full logcat before printing or saving them.
val deadlineMillis = startMillis + totalTimeoutMillis

// Wait for the Google Map accessibility node to appear within the full timeout budget
uiDevice.wait(Until.hasObject(By.descContains("Google Map")), totalTimeoutMillis)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Being the result of uiDevice.wait ignored, if the map has no "Google Map" description we now spend the whole 30s here and then return without any settle check (before it was 3s + 5s). Could we check the result and fall back to the full screen, or at least log which node we didn't find?

Comment on lines +152 to +154
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: after restoring the flag, every following Thread.sleep throws directly, so the loop takes screenshots without pause until the deadline. What about stopping the wait here?

Suggested change
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
}
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
throw IllegalStateException("Interrupted while waiting for map rendering", e)
}

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! I pushed two small fixes for the logcat step: each line of script runs in its own shell, so the if/fi block was failing even with the tests green, and the API keys are now redacted (the Maps SDK logs them on authorization failures, and the uploaded artifact is not masked). Should we keep this step now, or is still temporary as the commit says?

This branch has not been deployed

No deployments
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.

2 participants