Fix FeedListViewModelTest flakiness at its actual root cause (issue #261) - #296
Merged
Conversation
) Two distinct bugs, not generic CI noise: - uiState_splitsPodcastAndOtherFeedsIntoFixedSections waited for `sections.any { isNotEmpty }`, which only requires one of the two sections to have settled. Room delivers each subscribed feed's Flow update from its own background invalidation-tracker thread, so the sections can populate at different times and the test could assert against a still-settling state. Wait for both feeds to have landed instead. - uiState_freezesUnreadCountWhileRefreshing and uiState_allReadFeedWithNoNewItems_unreadCountNeverRisesDuringRefresh used a real 300ms MockResponse delay to keep the refresh coroutine genuinely in-flight while the test wrote to the DB, racing real wall-clock time against the virtual test dispatcher. Replace it with a MockWebServer Dispatcher blocked on a CountDownLatch the test releases explicitly -- same real dispatcher-switch mechanics, no more racing a fixed duration against CI runner load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #261
Summary
Root-caused rather than contained (unlike the sibling
ArticleListViewModelTest/SettingsViewModelTestflakiness, issues #54/#60/#215, where three separate root-cause attempts failed and a CI-only class skip was the only thing that stuck -- see repo history). Downloaded the actual CI failure artifacts from the run that failed this issue and found two distinct, understandable bugs:uiState_splitsPodcastAndOtherFeedsIntoFixedSectionsfailed withexpected:<[2]> but was:<[]>-- its wait predicate wassections.any { isNotEmpty }, which only requires one of the two sections to have settled. Room delivers each subscribed feed's Flow update from its own background invalidation-tracker thread, so the sections can populate at different times, and the test could assert against a still-settling state. Fixed to wait for both feeds to have landed (sections.sumOf { it.feeds.size } == 2).uiState_freezesUnreadCountWhileRefreshingfailed withexpected:<1> but was:<2>-- it (and a sibling test,uiState_allReadFeedWithNoNewItems_unreadCountNeverRisesDuringRefresh, same pattern) used a real 300msMockResponsedelay to keep the refresh coroutine genuinely in-flight while the test writes to the DB mid-refresh, racing real wall-clock time against the virtual test dispatcher -- exactly the failure mode a loaded CI runner exposes. Replaced with aMockWebServerDispatcherblocked on aCountDownLatchthe test releases explicitly instead of a real network response body reaching completion after a hoped-to-be-long-enough delay: same real dispatcher-switch mechanics (the network call still genuinely suspends onDispatchers.IO), no more racing a fixed duration.Test plan
FeedListViewModelTestin isolation, 10/10 clean rerunstestDebugUnitTestsuite, 3/3 runs --FeedListViewModelTest100% clean each time (the one unrelated failure each run was the already-trackedArticleListViewModelTestclass, issues Investigate CI-only hang in SettingsViewModelTest #54/Investigate CI-only failure in ArticleListViewModelTest.defaultToAllArticleViewSetting_showsAllByDefault #60/ArticleListViewModelTest: refresh() corrupts next test's StateFlow wait (lost wakeup) #215)