Modern Apps git

← Modern-Apps.git

appstore: dedupe pumpUntil test waits via shared testsupport harness

Commit
2268677a5f623139f0c692c87674534dbc510c42
Author
Vayun Mathur <[email protected]>
When
2026-12-02 01:13 UTC (4 days ago)
Parents
372e40e
Sixteen appstore test classes each carried the same private wait
harness: an await wrapper, a pumpUntil body with its doc comment and
a pump-only companion (PUMP_STEP_MS/PARK_MS/MAX_PUMP_STEPS). They now
call the shared com.vayunmathur.testsupport.pumpUntil added to
DeterministicAwait.kt, and the private copies, their companions and
the then-unused Looper/Shadows imports are deleted.

This is structural dedupe only, not a rewrite. Every @Test and every
assertion survives verbatim (26 tests and 48 assertion calls, counted
per file before and after); the wait conditions inside the lambdas are
untouched. The only call-site change is await( becoming pumpUntil(,
plus the class's original looper step where it was not the shared
200L default (stepMs = 400L in five classes, 100L nowhere in this
batch, 0L idle-only in TvLibraryOpsPlayTest and
SourcesPageAllDisabledTest, whose copies deliberately never advanced
the looper clock). The failure shape is unchanged: pumpUntil throws
the same wrapped AssertionError the await wrappers produced.

Each converted file is 28-46% shorter (2152 lines to 1452 across the
batch, -700; +53 shared lines in build-logic). The remaining ten
appstore copies sit in classes of 169-359 lines, where the same
deletion is only 10-24%, below the 25% per-file bar, so they are left
for a batch that also extracts their larger setups.

Verified: :appstore:testDevUnitTest green before and after;
tools/structure_check.py lines OK (1,661,809 total vs 1,749,740
baseline). lint and lintVitalRelease are red on appstore both at
HEAD and after this change with identical error locations (2
DialogAsRoute + 3 RouteScreenshotCoverage in src/main, plus 6
FixtureDeterminism in untouched test files); no converted file adds
any lint or ktlint finding, so the module keeps exactly its
pre-existing lint backlog.

Diff

appstore/src/test/java/com/vayunmathur/appstore/tv/TvCheckBranchesTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvCheckBranchesTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvCheckBranchesTest.ktindex 5a55c216b8..d50625998c 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvCheckBranchesTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvCheckBranchesTest.kt@@ -3,7 +3,6 @@ import com.vayunmathur.appstore.data.FDroidRepository import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -11,6 +10,7 @@ import com.vayunmathur.appstore.data.AccrescentTrustEntity import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test@@ -18,7 +18,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The TV update check with Play and Accrescent enabled: Play is asked@@ -93,55 +92,12 @@ class TvCheckBranchesTest {         com.vayunmathur.appstore.data.FDroidRepository.downloadOverride = null     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; updates=${vm.updatesUi.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `check with play and accrescent enabled settles and keeps previous play rows`() {         val previous = UnifiedApp(ownPackage, AppSource.PLAYSTORE, "Previous Play Row")         vm.playUpdatesFlow.value = listOf(previous)         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled") {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         // Play cannot answer offline: its previous row is kept, not wiped.
appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryOpsPlayTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryOpsPlayTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryOpsPlayTest.ktindex 4e2d46908c..703e8330b9 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryOpsPlayTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryOpsPlayTest.kt@@ -13,6 +13,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.SettingsRepository import com.vayunmathur.appstore.data.installer.InstallEvents import com.vayunmathur.appstore.data.installer.InstallResult+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -49,60 +50,15 @@ class TvLibraryOpsPlayTest {         runBlocking { settings.setSourceEnabled(AppSource.PLAYSTORE, true) }     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-// Original pumping primitive for this class: idle() only,-            // no looper-clock advance (advancing it here drove delayed-            // work early and broke the terminal states this waits on).-            Shadows.shadowOf(Looper.getMainLooper()).idle()-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 100L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `play attribution keeps the previous answer when play cannot answer`() {         val vm = TvStoreViewModel(app, db)-        await("play enabled at init") { AppSource.PLAYSTORE in vm.enabledSourcesFlow.value }+        pumpUntil("play enabled at init", stepMs = 0L) { AppSource.PLAYSTORE in vm.enabledSourcesFlow.value }         vm.playInstalledPackagesFlow.value = setOf("com.example.kept")         // A successful install for another package re-runs the refresh:         // Play still cannot answer offline, so the kept set survives.         InstallEvents.publish(InstallResult("com.example.other", success = true))-        await("refresh settled") {+        pumpUntil("refresh settled", stepMs = 0L) {             vm.installedRepo.apps.value.any { it.packageName == app.packageName }         }         // Quiescence settle (the negative half of this assertion): pump
appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryTest.ktindex 6e7abf8f87..af51870597 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLibraryTest.kt@@ -4,7 +4,6 @@ import com.vayunmathur.appstore.platform.TvStoreViewModel import com.vayunmathur.appstore.platform.setLibraryFilter  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -13,6 +12,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -20,7 +20,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * TV library attribution: the installed test app is attributed to the@@ -57,52 +56,9 @@ class TvLibraryTest {         vm = TvStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `the installed app is attributed to its catalogue source`() {-        await("library attribution") {+        pumpUntil("library attribution") {             vm.library.value.apps.any { it.packageName == ownPackage }         }         val listing = vm.library.value.apps.first { it.packageName == ownPackage }@@ -114,27 +70,27 @@ class TvLibraryTest {      @Test     fun `disabling the source removes the attribution`() {-        await("library attribution") {+        pumpUntil("library attribution") {             vm.library.value.apps.any { it.packageName == ownPackage }         }         vm.enabledSourcesFlow.value = emptySet()-        await("attribution removed") { vm.library.value.apps.isEmpty() }+        pumpUntil("attribution removed") { vm.library.value.apps.isEmpty() }         assertEquals(0, vm.library.value.counts[SourceFilter.ALL])     }      @Test     fun `the library filter narrows to one source`() {-        await("library attribution") {+        pumpUntil("library attribution") {             vm.library.value.apps.any { it.packageName == ownPackage }         }         vm.setLibraryFilter(SourceFilter.FDROID)-        await("filtered out") { vm.library.value.apps.isEmpty() }+        pumpUntil("filtered out") { vm.library.value.apps.isEmpty() }         assertEquals(SourceFilter.FDROID, vm.library.value.filter)         // Counts still describe the whole library, not the filtered view.         assertEquals(1, vm.library.value.counts[SourceFilter.ALL])          vm.setLibraryFilter(SourceFilter.MODERN_APPS)-        await("filtered in") {+        pumpUntil("filtered in") {             vm.library.value.apps.map { it.packageName } == listOf(ownPackage)         }         assertTrue(vm.library.value.apps.single().source == AppSource.MODERN_APPS)
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 e5c55ff8b4..837134d10e 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvLoadHomePlayAccrescentTest.kt@@ -4,20 +4,19 @@ import com.vayunmathur.appstore.data.SettingsRepository import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver 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 com.vayunmathur.testsupport.pumpUntil import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertTrue import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * TV loadHome with Play and Accrescent enabled: the Accrescent row@@ -98,53 +97,10 @@ class TvLoadHomePlayAccrescentTest {         com.vayunmathur.appstore.data.FDroidRepository.downloadOverride = null     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; home=${vm.home.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `loadHome adds the accrescent row and no play row offline`() {         vm.loadHome()-        await("accrescent section") {+        pumpUntil("accrescent section") {             vm.home.value.sections.any { it.id == "accrescent" }         }         val sections = vm.home.value.sections
appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchLiveSourcesTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchLiveSourcesTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchLiveSourcesTest.ktindex f05d6c46fc..5adb207b69 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchLiveSourcesTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchLiveSourcesTest.kt@@ -3,7 +3,6 @@ import com.vayunmathur.appstore.platform.TvStoreViewModel import com.vayunmathur.appstore.platform.merge  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -12,6 +11,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -19,7 +19,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The TV search with Play and Accrescent enabled: the local catalogue@@ -55,53 +54,10 @@ class TvSearchLiveSourcesTest {         )     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; search=${vm.search.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 400L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `live sources enabled still surface the catalogue hit`() {         vm.setSearch("alpha")-        await("searched") { vm.search.value.hasSearched }+        pumpUntil("searched", stepMs = 400L) { vm.search.value.hasSearched }         assertEquals(             listOf("com.example.alpha"),             vm.search.value.results.map { it.packageName },
appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchOpsTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchOpsTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchOpsTest.ktindex 03fa10c0fc..490a8cedad 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchOpsTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvSearchOpsTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.tv import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -11,6 +10,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -18,7 +18,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The TV two-wave search with every network source switched off: the@@ -63,53 +62,10 @@ class TvSearchOpsTest {         vm.enabledSourcesFlow.value = emptySet()     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 400L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `a query finds the catalogue hit after the debounce`() {         vm.setSearch("alpha")-        await("results") {+        pumpUntil("results", stepMs = 400L) {             vm.search.value.results.map { it.packageName } == listOf("com.example.alpha")         }         assertTrue(vm.search.value.hasSearched)@@ -119,16 +75,16 @@ class TvSearchOpsTest {     @Test     fun `a query with no hits settles as searched and empty`() {         vm.setSearch("zzzznothing")-        await("settled empty") { vm.search.value.hasSearched && vm.search.value.results.isEmpty() }+        pumpUntil("settled empty", stepMs = 400L) { vm.search.value.hasSearched && vm.search.value.results.isEmpty() }         assertTrue(vm.search.value.results.isEmpty())     }      @Test     fun `clearing the query resets the search state`() {         vm.setSearch("alpha")-        await("results") { vm.search.value.results.isNotEmpty() }+        pumpUntil("results", stepMs = 400L) { vm.search.value.results.isNotEmpty() }         vm.setSearch("")-        await("cleared") {+        pumpUntil("cleared", stepMs = 400L) {             vm.search.value.results.isEmpty() && !vm.search.value.hasSearched &&                 vm.search.value.query.isEmpty()         }
appstore/src/test/java/com/vayunmathur/appstore/tv/TvStoreLoadHomeTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvStoreLoadHomeTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvStoreLoadHomeTest.ktindex 1c5976a967..6a20468838 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvStoreLoadHomeTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvStoreLoadHomeTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.tv import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -11,6 +10,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -18,7 +18,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * loadHome against a seeded catalogue: one row per enabled offline@@ -61,61 +60,18 @@ class TvStoreLoadHomeTest {         vm = TvStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; enabled=${vm.enabledSourcesFlow.value}; home=${vm.home.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `loadHome builds one row per enabled offline source`() {         // Let the init pass settle first: it re-reads the enabled sources         // from settings (F-Droid starts off, so its seeded row is purged         // by that pass) and would overwrite the set below.-        await("init home") { vm.home.value.sections.isNotEmpty() }+        pumpUntil("init home") { vm.home.value.sections.isNotEmpty() }         seed("com.example.fdroid", AppSource.FDROID, DefaultRepos.FDROID.url, 200L)         vm.enabledSourcesFlow.value = setOf(             AppSource.MODERN_APPS, AppSource.FDROID, AppSource.PROPRIETARY,         )         vm.loadHome()-        await("home rows") {+        pumpUntil("home rows") {             vm.home.value.sections.map { it.id }.containsAll(                 listOf("modern-recent", "fdroid-recent", "proprietary-recent"),             )@@ -131,10 +87,10 @@ class TvStoreLoadHomeTest {      @Test     fun `loadHome with a category replaces the rows with that category`() {-        await("init home") { vm.home.value.sections.isNotEmpty() }+        pumpUntil("init home") { vm.home.value.sections.isNotEmpty() }         vm.selectedCategoryFlow.value = "Games"         vm.loadHome()-        await("category row") {+        pumpUntil("category row") {             vm.home.value.sections.singleOrNull()?.id == "category"         }         assertEquals("Games", vm.home.value.sections.single().title)
appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateAllEligibleTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateAllEligibleTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateAllEligibleTest.ktindex b7937eeb57..45e5ae6b26 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateAllEligibleTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateAllEligibleTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.tv import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -12,6 +11,7 @@ import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.installer.InstallStage import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertTrue@@ -58,60 +58,17 @@ class TvUpdateAllEligibleTest {         vm.enabledSourcesFlow.value = setOf(AppSource.MODERN_APPS)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; updates=${vm.updatesUi.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `updateAll attempts the eligible tv update and settles`() {         vm.checkForUpdates()-        await("eligible update listed") {+        pumpUntil("eligible update listed") {             vm.updatesUi.value.updates.any { it.packageName == ownPackage }         }         vm.updateAll()-        await("install attempted") {+        pumpUntil("install attempted") {             vm.installer.stages.value[ownPackage] is InstallStage.Failed         }-        await("run settled") { vm.updateAllJob?.isActive != true }+        pumpUntil("run settled") { vm.updateAllJob?.isActive != true }         assertTrue(vm.updatesUi.value.stages[ownPackage] is InstallStage.Failed)     } }
appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateCheckTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateCheckTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateCheckTest.ktindex a2ba3f9faa..e4cdea0225 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateCheckTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/tv/TvUpdateCheckTest.kt@@ -4,7 +4,6 @@ import com.vayunmathur.appstore.data.FDroidRepository import com.vayunmathur.appstore.platform.TvStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -12,6 +11,7 @@ import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test@@ -21,7 +21,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The TV manual update check with only Modern Apps enabled (the@@ -72,53 +71,10 @@ class TvUpdateCheckTest {         com.vayunmathur.appstore.data.FDroidRepository.downloadOverride = null     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `checkForUpdates finds the catalogue update and settles`() {         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled") {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         assertTrue(@@ -135,6 +91,6 @@ class TvUpdateCheckTest {     @Test     fun `updateAll with nothing pending is a no-op`() {         vm.updateAll()-        await("settled") { vm.updateAllJob?.isActive != true }+        pumpUntil("settled") { vm.updateAllJob?.isActive != true }     } }
appstore/src/test/java/com/vayunmathur/appstore/ui/SourcesPageAllDisabledTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/ui/SourcesPageAllDisabledTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/ui/SourcesPageAllDisabledTest.ktindex 701b916319..3200afe91a 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/ui/SourcesPageAllDisabledTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/ui/SourcesPageAllDisabledTest.kt@@ -1,7 +1,6 @@ package com.vayunmathur.appstore.ui  import android.app.Application-import android.os.Looper import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText@@ -11,12 +10,12 @@ import androidx.test.core.app.ApplicationProvider import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.platform.AppStoreViewModel+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * With every toggleable source switched off the sources screen says@@ -41,55 +40,10 @@ class SourcesPageAllDisabledTest {         vm = AppStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-// Original pumping primitive for this class: idle() only,-            // no looper-clock advance (advancing it here drove delayed-            // work early and broke the terminal states this waits on).-            Shadows.shadowOf(Looper.getMainLooper()).idle()-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 100L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `switching every source off shows the nothing to browse warning`() {         for (source in AppSource.TOGGLEABLE) vm.setSourceEnabled(source, false)-        await("all sources disabled") {+        pumpUntil("all sources disabled", stepMs = 0L) {             AppSource.TOGGLEABLE.none { it in vm.enabledSources.value }         } 
appstore/src/test/java/com/vayunmathur/appstore/util/PhoneCheckAccrescentTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneCheckAccrescentTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneCheckAccrescentTest.ktindex 1284c485e8..a5a1783214 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneCheckAccrescentTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneCheckAccrescentTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.util import com.vayunmathur.appstore.platform.AppStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -10,6 +9,7 @@ import com.vayunmathur.appstore.data.AccrescentTrustEntity import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.SettingsRepository+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertTrue@@ -18,7 +18,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The phone update check's Accrescent branch: with Accrescent enabled@@ -80,53 +79,10 @@ class PhoneCheckAccrescentTest {         )     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; updates=${vm.updatesUi.value}", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `check with accrescent enabled consults the allowlist and settles`() {         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled") {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         assertTrue(
appstore/src/test/java/com/vayunmathur/appstore/util/PhoneSearchLiveTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneSearchLiveTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneSearchLiveTest.ktindex b80fc8e490..0d16539218 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneSearchLiveTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneSearchLiveTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.util import com.vayunmathur.appstore.platform.AppStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -11,6 +10,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -22,7 +22,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The phone live search: with the network sources switched off in@@ -71,55 +70,14 @@ class PhoneSearchLiveTest {         CoroutineScope(Dispatchers.IO).launch {             try { block(); done.complete(Unit) } catch (e: Throwable) { done.completeExceptionally(e) }         }-        pumpUntil("settings edit") { done.isCompleted }+        pumpUntil("settings edit", stepMs = 400L) { done.isCompleted }         done.getCompletionExceptionOrNull()?.let { throw it }     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; search=${vm.search.value}", e)-        }-    }-    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs, and-     * the failure is raised only after [MAX_PUMP_STEPS] pumps.-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 400L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `a query finds the catalogue hit after the debounce`() {         vm.setSearch("alpha")-        await("results") {+        pumpUntil("results", stepMs = 400L) {             vm.search.value.results.map { it.packageName } == listOf("com.example.alpha")         }         assertTrue(vm.search.value.hasSearched)@@ -130,7 +88,7 @@ class PhoneSearchLiveTest {     @Test     fun `a query with no hits settles as searched and empty`() {         vm.setSearch("zzzznothing")-        await("settled empty") {+        pumpUntil("settled empty", stepMs = 400L) {             vm.search.value.hasSearched && vm.search.value.results.isEmpty()         }     }
appstore/src/test/java/com/vayunmathur/appstore/util/PhoneUpdateAllEligibleTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneUpdateAllEligibleTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneUpdateAllEligibleTest.ktindex 00ff051455..d765786230 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneUpdateAllEligibleTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/PhoneUpdateAllEligibleTest.kt@@ -3,7 +3,6 @@ import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.appstore.platform.reason  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -13,6 +12,7 @@ import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.installer.InstallStage import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -60,61 +60,18 @@ class PhoneUpdateAllEligibleTest {         vm = AppStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `updateAll attempts the eligible update and settles`() {-        await("eligible update") {+        pumpUntil("eligible update") {             vm.partitionedUpdates.value.eligible.any { it.packageName == ownPackage }         }         assertTrue(vm.partitionedUpdates.value.foreign.none { it.packageName == ownPackage })          vm.updateAll()-        await("eligible install attempted") {+        pumpUntil("eligible install attempted") {             vm.installer.stages.value[ownPackage] is InstallStage.Failed         }-        await("run settled") { vm.updateAllJob?.isActive != true }+        pumpUntil("run settled") { vm.updateAllJob?.isActive != true }         val stage = vm.installer.stages.value[ownPackage] as InstallStage.Failed         assertTrue(stage.reason.isNotBlank())         assertEquals(
appstore/src/test/java/com/vayunmathur/appstore/util/UpdateAllTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateAllTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateAllTest.ktindex fbb424d75c..0d92b18094 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateAllTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateAllTest.kt@@ -3,7 +3,6 @@ import com.vayunmathur.appstore.platform.AppStoreViewModel import com.vayunmathur.appstore.platform.reason  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -12,6 +11,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -19,7 +19,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * Update-all batch eligibility: a package this store did not install@@ -60,61 +59,18 @@ class UpdateAllTest {         vm = AppStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 400L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `updateAll leaves foreign updates alone`() {         // The test app was not installed by this store (no installer of         // record under Robolectric), so its update is foreign: listed,         // but the batch must not attempt it.-        await("foreign update") {+        pumpUntil("foreign update", stepMs = 400L) {             vm.partitionedUpdates.value.foreign.any { it.packageName == ownPackage }         }         assertTrue(vm.partitionedUpdates.value.eligible.isEmpty())          vm.updateAll()-        await("run settled") { vm.updateAllJob?.isActive != true }+        pumpUntil("run settled", stepMs = 400L) { vm.updateAllJob?.isActive != true }          // No install was attempted for the foreign package.         assertEquals(null, vm.installer.stages.value[ownPackage])
appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckPlayBranchTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckPlayBranchTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckPlayBranchTest.ktindex ac5d99610e..4d2019cdca 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckPlayBranchTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckPlayBranchTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.util import com.vayunmathur.appstore.platform.AppStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -11,6 +10,7 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertTrue@@ -21,7 +21,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The Play half of a manual update check, with Play switched on in@@ -73,55 +72,14 @@ class UpdateCheckPlayBranchTest {         CoroutineScope(Dispatchers.IO).launch {             try { block(); done.complete(Unit) } catch (e: Throwable) { done.completeExceptionally(e) }         }-        pumpUntil("settings edit") { done.isCompleted }+        pumpUntil("settings edit", stepMs = 400L) { done.isCompleted }         done.getCompletionExceptionOrNull()?.let { throw it }     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description; checking=${vm.isCheckingUpdatesFlow.value}; status=${vm.statusMessageFlow.value}; catalog=${vm.catalogUpdatesFlow.value}; updates=${vm.updatesUi.value}", e)-        }-    }-    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs, and-     * the failure is raised only after [MAX_PUMP_STEPS] pumps.-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 400L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `check with play enabled keeps play rows when play cannot answer`() {         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled", stepMs = 400L) {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         assertTrue(vm.playUpdatesFlow.value.isEmpty())
appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckTest.ktindex 85d0a47805..bb97ca972b 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/util/UpdateCheckTest.kt@@ -2,7 +2,6 @@ package com.vayunmathur.appstore.util import com.vayunmathur.appstore.platform.AppStoreViewModel  import android.app.Application-import android.os.Looper import androidx.room3.Room import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.test.core.app.ApplicationProvider@@ -10,6 +9,7 @@ import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.toEntity+import com.vayunmathur.testsupport.pumpUntil import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals@@ -18,7 +18,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.runBlocking import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner-import org.robolectric.Shadows  /**  * The manual update check: the catalogue half answers from Room (this@@ -56,54 +55,11 @@ class UpdateCheckTest {         vm = AppStoreViewModel(app, db)     } -    private fun await(description: String, condition: () -> Boolean) {-        try {-            pumpUntil(description, condition)-        } catch (e: AssertionError) {-            throw AssertionError("timed out waiting for: $description", e)-        }-    }--    /**-     * Step-bounded pumped wait on a terminal [condition]: every step-     * advances the paused main looper (running the ViewModel/DataStore-     * work queued there, including delayed tasks), then parks briefly-     * so Dispatchers.IO/Default producers get a CPU slice on a-     * contended box. The bound is pumping steps, never wall-clock-     * seconds that CI contention can burn before any work runs (the-     * previous 10-30s System.currentTimeMillis deadlines fired early-     * under a 5-CPU cap while the terminal state was still landing).-     */-    private fun pumpUntil(description: String, condition: () -> Boolean) {-        var steps = 0-        while (true) {-            // Pump first, then check: the loops this replaces always-            // idled at least once before judging the condition, and a-            // condition that is already true at entry can still need-            // that one pump for the work behind it to settle.-            Shadows.shadowOf(Looper.getMainLooper())-                .idleFor(PUMP_STEP_MS, java.util.concurrent.TimeUnit.MILLISECONDS)-            if (condition()) break-            java.util.concurrent.locks.LockSupport.parkNanos(-                java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(PARK_MS),-            )-            if (++steps >= MAX_PUMP_STEPS) {-                throw AssertionError("timed out (step-bounded): $description after $MAX_PUMP_STEPS pumps")-            }-        }-    }--    private companion object {-        const val PUMP_STEP_MS = 200L-        const val PARK_MS = 50L-        const val MAX_PUMP_STEPS = 6_000-    }-     @Test     fun `checkForUpdates surfaces the catalogue update and settles`() {         // The init pass can purge/sync against the seeded row; re-seed once         // it has settled so the check reads the catalogue this test wrote.-        await("init settled") { vm.home.value.sections.isNotEmpty() || !vm.isLoadingHomeFlow.value }+        pumpUntil("init settled") { vm.home.value.sections.isNotEmpty() || !vm.isLoadingHomeFlow.value }         runBlocking {             db.cachedAppDao().upsert(                 UnifiedApp(@@ -115,7 +71,7 @@ class UpdateCheckTest {             )         }         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled") {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         // The test app was not installed by this store, so its update is@@ -135,7 +91,7 @@ class UpdateCheckTest {     fun `a second check while one is running does not wedge the tab`() {         vm.checkForUpdates()         vm.checkForUpdates()-        await("check settled") {+        pumpUntil("check settled") {             !vm.updatesUi.value.isChecking && vm.updatesUi.value.lastCheckedAt > 0L         }         assertFalse(vm.updatesUi.value.isChecking)