Repository navigation
test(home): stop a Home test's mock request from outliving the test - #575
Conversation
…t dispatcher realtimeSignalsDuringARefreshRunOneMoreRefreshAfterIt returned as soon as its follow-up request entered MockEngine. MockEngine had no dispatcher, so it answered on a real IO thread after tearDown had reset Dispatchers.Main. The late response resumed HomeViewModel on the missing Main dispatcher, and kotlinx-coroutines-test reported that against the next runTest in the JVM, usually PersonalListViewModelGenerationTest. The file's Home clients now run MockEngine on the test's dispatcher, so no request outlives the test on another thread. Closes #562 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Problem
Closes #562
Related issue: N/A
Validation tasks: none
PersonalListViewModelGenerationTest > aResetSupersededByARefreshDoesNotStrandIsLoadingfailed intermittently in:shared:testDebugUnitTest. On 2026-10-14 it failed CI and the release workflow's unit-test step five times. That test was the victim. The leak came fromHomeViewModelCacheIdentityTest.realtimeSignalsDuringARefreshRunOneMoreRefreshAfterIt.That test returned as soon as its follow-up request entered MockEngine. MockEngine had no dispatcher, so it answered on a real IO thread, sometimes after
@AfterTesthad calledDispatchers.resetMain(). The late response finishedHomeSectionsV2Api.list()'swithContext(decodeDispatcher)and resumedHomeViewModelonDispatchers.Main, which no longer existed. kotlinx-coroutines-test then reported the error against the nextrunTestin the JVM asUncaughtExceptionsBeforeTest.The CI trace matches this: the uncaught exception ran on
DefaultDispatcher-worker-3 @call-context#6086, Ktor's call coroutine, resuming awithContexton anUnconfinedTestDispatcher.Approach
The three Home clients in
HomeViewModelCacheIdentityTestnow build MockEngine withMockEngineConfig.dispatcherset to the test's own dispatcher, asHomeScreenV2Testalready does. No mocked request can outlive the test on another thread. Production code is unchanged, and no test is retried, skipped, or ignored.Validation
HomeViewModelCacheIdentityTestandPersonalListViewModelGenerationTesttogether failed 13 of 25 times, with the same exception chain as CI. Failures alternated run to run, which fits Gradle running the previously failed class first.setUp/tearDown, left Main reset for 20 ms, then started an emptyrunTest. Before the fix, the realtime test leaked into the nextrunTestin 348 of 600 iterations and the other two Home tests in 0 of 1,200. After the fix, all three leaked in 0 of 600.:shared:testDebugUnitTestafter the fix: 15 of 15 runs passed, 1,949 tests each, and noDispatchers.Mainerrors anywhere in the test output.Evidence
No user-visible change. Reproduction steps, CI and local traces, and test logs:
Evidence: https://evidence.siloserver.org/r/silo-android/pr-575/
Risks
None identified. The change touches only one test file.
Follow-up, not in this PR:
android-shared'sMembershipActivationTestalso leaves view model work in flight on real threads when tests return. It runs under Robolectric, so Main falls back to the looper and this crash can't happen there. Joining its view model jobs beforeresetMain()would make it deterministic.Checklist
AI Disclosure
gh), Gradleclaude-opus-5-5)setMaintests for the same leak and found only the follow-up above.🤖 Generated with Claude Code
Note
Run Home test mock requests on the test dispatcher via shared
homeClientfactoryAdds a private
homeClientfactory in HomeViewModelCacheIdentityTest.kt that builds the mock HTTP client with content negotiation and the test instance's dispatcher. Replaces inlineHttpClient/MockEngineconstruction in three tests with the shared factory. Behavioral Change: mock request handlers now run on therunTestdispatcher, so blocked and follow-up requests resume under test control instead of the engine's default dispatcher.Macroscope summarized 930ef37.