Skip to content

Fix flaky instrumentation tests, Compose timeouts, and NPE crashes#540

Open
temcguir wants to merge 6 commits into
mainfrom
temcguir/fix-timeouts-and-crashes
Open

Fix flaky instrumentation tests, Compose timeouts, and NPE crashes#540
temcguir wants to merge 6 commits into
mainfrom
temcguir/fix-timeouts-and-crashes

Conversation

@temcguir

Copy link
Copy Markdown
Collaborator

This pull request introduces several stability fixes for Jetpack Camera App's instrumentation tests, which previously suffered from intermittent timeouts and crashes when running on emulators.

Changes:

  • Fixed a race condition in PreviewViewModel: Events from the zero-capacity _captureEvents Rendezvous Channel were previously being blocked if consumed rapidly. We've split the event pipeline into _incomingCaptureEvents (an UNLIMITED capacity channel) and _outgoingCaptureEvents to cleanly bridge the events from the CaptureController to the Compose UI. This resolves ComposeTimeoutException flakes in Snackbar assertions and test runners.
  • Accommodated emulator slowness: Increased DEFAULT_TIMEOUT_MILLIS in UiTestUtil.kt from 5 seconds to 15 seconds. This provides enough buffer for slower emulators transitioning back to the capture screen in CaptureModeSettingsTest without artificially flaking.
  • Fixed a reproducible startup crash: Replaced instrumentation.context.applicationContext with instrumentation.targetContext.applicationContext inside CameraXCameraSystemTest. This resolves a 100% reproducible NullPointerException during test initialization.
  • Code cleanups: Fixed Kotlin linter warnings, removed unused imports, and eliminated dead testing code in PreviewViewModel.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors several UI and camera system tests, adjusting timeouts, replacing forEach loops with standard for loops, and splitting the capture events channel in PreviewViewModel into incoming and outgoing channels. Feedback focuses on buffering the outgoing capture events channel to prevent potential deadlocks, simplifying semantics node checks in ComposeTestRuleExt.kt, removing redundant and unidiomatic 'val unused' assignments, and using Kotlin's native @Suppress annotation instead of Java's @SuppressWarnings.

Comment thread app/src/androidTest/java/com/google/jetpackcamera/utils/ComposeTestRuleExt.kt Outdated
Comment thread app/src/androidTest/java/com/google/jetpackcamera/utils/ComposeTestRuleExt.kt Outdated
Comment thread app/src/androidTest/java/com/google/jetpackcamera/utils/ComposeTestRuleExt.kt Outdated
Comment thread app/src/androidTest/java/com/google/jetpackcamera/utils/UiTestUtil.kt Outdated
@temcguir
temcguir requested a review from davidjiagoogle July 15, 2026 00:04
@temcguir
temcguir force-pushed the temcguir/fix-timeouts-and-crashes branch from 03f6350 to 1946e34 Compare July 15, 2026 00:11
@temcguir
temcguir force-pushed the temcguir/fix-timeouts-and-crashes branch 2 times, most recently from 04c048c to 27ac92c Compare July 15, 2026 00:17
@temcguir
temcguir force-pushed the temcguir/fix-timeouts-and-crashes branch from 27ac92c to 202769b Compare July 15, 2026 01:42
@davidjiagoogle

Copy link
Copy Markdown
Collaborator

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

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