Modern Apps git

← Modern-Apps.git

appstore: make TvLoadHomePlayAccrescentTest order-independent

Commit
a993faa21d546ef37dda118dbe0cd79636546ab8
Author
Vayun Mathur <[email protected]>
When
2026-11-14 23:26 UTC (21 days ago)
Parents
0e98913
In the full suite this test timed out waiting for the Accrescent
section: the TV ViewModel's init reloads the enabled-source set
from settings (overwriting the flow the test set) and runs a
first-run catalogue sync, so with live network the real
catalogue was imported and whether the Accrescent row appeared
depended on coroutine timing. Persist the same enabled set to
settings before constructing the ViewModel (the pattern the
phone check test already uses) and fail the catalogue downloads
like the other offline tests. Assertions unchanged.

Verified: targeted :appstore:testDevUnitTest run (see final
full-suite run).

Diff

appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.ktindex bedecf189d..7626be8905 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt@@ -8,6 +8,7 @@ import androidx.test.core.app.ApplicationProvider import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp+import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertTrue@@ -27,7 +28,27 @@ class TvLoadHomePlayAccrescentTest {      @BeforeTest     fun setUp() {+        // Hermetic offline: catalogue downloads fail, so the ViewModel's+        // first-run sync fails closed instead of importing the real+        // catalogue, whatever network the test host happens to have.+        com.vayunmathur.appstore.data.FDroidRepository.downloadOverride = { url, _ ->+            throw java.io.IOException("offline test double for $url")+        }         val app = ApplicationProvider.getApplicationContext<Application>()+        // The ViewModel's init reloads the enabled set from settings and+        // would overwrite the flow set below (a race that made this test+        // depend on coroutine timing): persist the same set first.+        kotlinx.coroutines.runBlocking {+            val settings = com.vayunmathur.appstore.data.SettingsRepository(+                app, kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.IO),+            )+            settings.setSourceEnabled(AppSource.PLAYSTORE, true)+            settings.setSourceEnabled(AppSource.ACCRESCENT, true)+            settings.setSourceEnabled(AppSource.MODERN_APPS, true)+            settings.setSourceEnabled(AppSource.FDROID, false)+            settings.setSourceEnabled(AppSource.IZZY, false)+            settings.setSourceEnabled(AppSource.PROPRIETARY, false)+        }         val db = Room.inMemoryDatabaseBuilder(app, AppDatabase::class.java)             .setDriver(BundledSQLiteDriver())             .allowMainThreadQueries()@@ -69,6 +90,11 @@ class TvLoadHomePlayAccrescentTest {         )     } +    @AfterTest+    fun tearDown() {+        com.vayunmathur.appstore.data.FDroidRepository.downloadOverride = null+    }+     private fun await(description: String, condition: () -> Boolean) {         val deadline = System.currentTimeMillis() + 30_000         while (System.currentTimeMillis() < deadline) {