Modern Apps git

← Modern-Apps.git

appstore: agree in memory before persisting a source toggle (653 tests)

Commit
c8edac886b5577d78d76cb8852bd0cfadeba5271
Author
Vayun Mathur <[email protected]>
When
2026-11-15 19:17 UTC (20 days ago)
Parents
1c63b61
Two CI-only failures:

- 'toggling a source off drops its in-memory contributions' timed
  out waiting for the flows to clear: TvStoreViewModel.setSourceEnabled
  awaited the DataStore write before touching any in-memory state,
  so observers (and the test) waited on storage IO for what is a
  pure memory update. Publish the new enabled set and forget the
  source's contributions first, then persist, purge the cache and
  reload — matching the function's 'make the rest of the store agree
  immediately' contract.

- 'rail renders and destinations can be selected' timed out waiting
  for destination content, which lands via viewModelScope
  (Dispatchers.Main) on Robolectric's paused main looper; waitUntil
  does not pump it. Idle the main looper inside the two waitUntil
  conditions.

Verified green 3x under TZ=UTC and TZ=America/New_York.

Diff

appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.ktindex 5268c440e7..959cefa789 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt@@ -473,12 +473,15 @@ class TvStoreViewModel(      */     fun setSourceEnabled(source: AppSource, enabled: Boolean) {         viewModelScope.launch {-            settings.setSourceEnabled(source, enabled)+            // In-memory state first: the screens (and anything observing the+            // flows) agree with the toggle as soon as this coroutine runs,+            // instead of after the DataStore write and cache purge below.             val next = if (enabled) enabledSourcesFlow.value + source else enabledSourcesFlow.value - source             enabledSourcesFlow.value = next-            catalog.purgeDisabled(next)             if (!enabled) forgetSource(source)             clearBrowse()+            settings.setSourceEnabled(source, enabled)+            catalog.purgeDisabled(next)             categoriesFlow.value = catalog.categories()             loadHome()             loadAccrescent(next)
appstore/src/test/java/com/vayunmathur/appstore/tv/TvMainActivityTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvMainActivityTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvMainActivityTest.ktindex 3c32bee3c3..0c6d8e6376 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvMainActivityTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvMainActivityTest.kt@@ -70,12 +70,17 @@ class TvMainActivityTest {             composeRule.onNodeWithText(label).assertIsDisplayed()         }         composeRule.onNodeWithText("Library").performSemanticsAction(SemanticsActions.RequestFocus)+        // The destination content lands via viewModelScope (Dispatchers.Main):+        // Robolectric's paused main looper only runs when idled, and the+        // compose rule's waitUntil does not pump it, so idle it per poll.         composeRule.waitUntil(timeoutMillis = 15_000) {+            org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()             composeRule.onAllNodesWithText("Apps you install are listed here", substring = true)                 .fetchSemanticsNodes().isNotEmpty()         }         composeRule.onNodeWithText("Sources").performSemanticsAction(SemanticsActions.RequestFocus)         composeRule.waitUntil(timeoutMillis = 15_000) {+            org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()             composeRule.onAllNodesWithText("Automatically install updates", substring = true)                 .fetchSemanticsNodes().isNotEmpty()         }