Skip to content

Tests: fix the Robolectric flakes (v2 Compose rule everywhere, Levels trial wait) - #21

Merged
ApolloF merged 2 commits into
mainfrom
ApolloF/flaky-tests
Oct 12, 2026
Merged

ApolloF merged 2 commits into
mainfrom
ApolloF/flaky-tests

Conversation

@ApolloF

@ApolloF ApolloF commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Main and the open release PRs fail on one random Robolectric test per run since the foss/play split runs the suite twice.

Cause. 34 of 46 Compose tests used the v1 test rule. Its unconfined effect dispatcher resumes the composition on whichever thread emitted a flow update (the view models' flowOn(Dispatchers.Default) pipelines), so frames ran off the main thread:

  • CalledFromWrongThreadException (TodayWeekPagerTest)
  • performMeasureAndLayout called during measure layout (AppNavTest)
  • half-applied frames: node not found (LevelsScreenTest), 30 s waits missed (Journal tests)

2429dfe fixed one test this way; this moves the other 34 to junit4.v2.createComposeRule, whose standard test dispatcher queues every resume for the test thread. Import change only.

LevelsGateTest (no Compose rule) waited for the trial end to equal the stored start + 14 days to the millisecond. Until the stored start reaches the state, the gate shows a trial from "now", a few ms off; on a loaded runner that update missed the 30 s wait. It now compares to the minute (the banner shows a date).

Verification (local).

  • :core:domain:test: 526 passed
  • testFossDebugUnitTest: full suite, 208 tests, 0 failures (before the LevelsGateTest edit)
  • testPlayDebugUnitTest: AppNav, LevelsScreen, TodayWeekPager, LevelsGate, JournalLogMenu, JournalHeaders, 18 tests, 0 failures

Not run locally: the full play suite, both lints, and the edited LevelsGateTest. The local runs were stopped by low memory, so CI covers those.

…s trial end to the minute

The v1 rule's unconfined effect dispatcher resumed frames on the background
thread that emitted a flow update (CalledFromWrongThreadException,
'performMeasureAndLayout called during measure layout', half-applied frames).
Since the foss/play split runs every Robolectric test twice, that hit almost
every CI run. 2429dfe fixed one test this way; this moves the other 34.

LevelsGateTest waited for the trial end to match the stored start to the
millisecond; until the stored start reaches the state it is a few ms off, and
on a loaded runner that update missed the 30 s wait.
@ApolloF
ApolloF enabled auto-merge (squash) October 12, 2026 14:30
CI run 38262804082 (foss): a sheet's text showed before its dialog window
took focus, so Espresso's back press went to the activity and closed the app
(NoActivityResumedException). Back on the dialog root waits for that focus.
@ApolloF
ApolloF merged commit 916b77c into main Oct 12, 2026
3 checks passed
@ApolloF
ApolloF deleted the ApolloF/flaky-tests branch October 12, 2026 14:51
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