Skip to content

Fix flaky SplashMdmActivity Robolectric test - #237

Open
patriciojofre wants to merge 1 commit into
masterfrom
test/splash-mdm-deterministic-asynctask
Open

patriciojofre wants to merge 1 commit into
masterfrom
test/splash-mdm-deterministic-asynctask

Conversation

@patriciojofre

Copy link
Copy Markdown
Member

Problem

givenRegistrationSucceededWithoutCaller_whenPostExecute_thenNavigatesToMain failed on #236 (run) with Result code should be RESULT_OK … expected:<-1> but was:<0>, while passing on master and locally.

SplashMdmActivity.onCreate starts the real MdmRegistrationTask on a background thread. With no MDM restrictions in the test it returns false, and its onPostExecute(false) calls setResult(RESULT_CANCELED). When that lands after the success result the test drives via reflection, it overwrites RESULT_OK, so whether the test passes depends on how fast the runner is.

Fix

setUp() sets ShadowPausedAsyncTask.overrideExecutor(task -> { }), so onCreate's task never runs. Every test already drives onPostExecute itself, and the failure-path test now checks only what its own call did to the views. Robolectric resets the override after each test (@Resetter), so no other class is affected.

Verification

  • Reproduced first: delaying the real task by 300 ms (a slow runner) made the test fail 3/3 with the exact CI message.
  • With the fix and the same "real task lands last" timing: 7/7 pass, 3/3 runs.
  • Clean fix: the class passed 20/20 runs; the full unit suite is 95/95.

./gradlew checkstyle fails on master too (unused imports in main code), and CI doesn't run it. This file adds no new violations.

🤖 Generated with Claude Code

onCreate starts a real MdmRegistrationTask on a background thread. With no
MDM restrictions it posts onPostExecute(false), and when that lands after
the test-driven success it overwrites RESULT_OK with RESULT_CANCELED, which
failed CI on #236. Tests drive onPostExecute themselves, so the real task
never runs now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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