Skip to content

Fix flaky instrumentation tests on slow CI emulators (part of #3211) - #3340

Draft
DenBond7 wants to merge 7 commits into
masterfrom
issue_3211_fix_password_protected_tests
Draft

DenBond7 wants to merge 7 commits into
masterfrom
issue_3211_fix_password_protected_tests

Conversation

@DenBond7

@DenBond7 DenBond7 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Issue #3211

I reproduced the failures on an emulator set up like CI: 1 core, 2 GB RAM, swiftshader_indirect, pinned to 2 host CPUs, and network configured by ci-wait-for-emulator.sh. I also used a CI logcat artifact. Most failures came from a few timing races.

Infrastructure

  • Long press instead of tap. On a slow emulator, a tap can take longer than long_press_timeout (400 ms) and turn into a long press (Overslept and turned a tap into a long press). The CI script now sets long_press_timeout to 1500.
  • "System UI isn't responding" dialog. It appears right after boot, takes the window focus and causes RootViewWithoutFocusException. BaseTest.dismissANRSystemDialogIfExists() looked for the text "wait", but the match is case-sensitive, so it never found the button. It now looks for android:id/aerr_wait and repeats while the dialog is shown.

Recipient lookup race

  • While the recipient's key is being looked up, the compose screen blocks sending with a "please wait" toast. It also shows the web portal password button for a moment, so the layout shifts.
  • New helper BaseTest.waitUntilRecipientChipIsSettled(): waits until the recipient chip keeps its final color for 1 s.
  • Used in the password-protected tests, ComposeScreenFlowTest#testEmptyEmailMsg and DraftsGmailAPITestCorrectSendingFlowTest.

Public key dialog race

  • After "Include public key", ChoosePublicKeyDialogFragment loads the key and closes itself. Until then it has the window focus, and clicking Send fails with NoMatchingViewException. This was confirmed in a CI logcat.
  • New helper BaseComposeGmailFlow.includeOwnPublicKey(): waits until the compose screen is in focus again.
  • Used in StandardWithPublicKeyComposeGmailApiFlow, EncryptedWithAttachmentsAndOwnPublicKeyComposeGmailApiFlow and PasswordProtectedEncryptedComposeGmailApiFlow.
  • ComposeScreenFlowTest#testSharePubKeyMultiply now waits for the key list.

Sending checks (doAfterSendingChecks, used by all sending tests)

  • Message not yet sent. Right after the Send click the message may not be in the outbox yet, so an empty outbox was taken as "sent". The check now also waits until the mock server receives the message (sentCache), and sentCache is now thread-safe.
  • Toolbar label. The toolbar is updated later than the database. It is now checked in a loop instead of after a fixed 1 s wait.
  • The same outbox check in DraftsGmailAPITestCorrectSendingFlowTest is fixed the same way.

Password-protected tests

  • …ReFetchConfigurationFlowTest is enabled again. The mock now returns the updated configuration when the test sets a flag, instead of counting requests. The flag is reset for every RetryRule attempt. Thread.sleep(2000) is replaced with a wait for the updated configuration in the database.

Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities

@DenBond7 DenBond7 changed the title Issue 3211 fix password protected tests Fix flaky instrumentation tests on slow CI emulators (part of #3211) Nov 14, 2026
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