Modern Apps git

← Modern-Apps.git

findfamily: await each derived flow and de-flake ceiling tick (#tests)

Commit
b3bad8056a20d696508122fca85a7fba432df3c3
Author
Vayun Mathur <[email protected]>
When
2026-11-16 18:25 UTC (19 days ago)
Parents
2f728ac
derivedFlowsReflectSeededData asserted awaitingRequestUsers
and usersByLocationName from the first snapshot after only
connectedUsers had landed; each WhileSubscribed flow computes
independently, so under CI load the others still held their
initial empty values (expected [Bob], was []). Each derived
flow is now awaited on its own condition, and the await helper
is step-counted instead of wall-clock (Robolectric's clock
runs ahead of real time). The same snapshot race in
FindFamilyViewModelRealRepoTest.derivedFlowsProjectSeededRows
(awaitingRequestUsers and usersById asserted right after the
connected projection) gets the same await treatment; it
failed a later combined run with the identical signature.

everyCheckMovesTheAlarmToOneCeilingLater (same combined runs):
the service's own heartbeat can fire a keep-alive tick during
setup and consume the "never attempted" due-ness, making the
test's first tick return no job. The attempt bookkeeping is
now reset before the first tick so it is deterministic.

Reproduced under TZ=UTC with 4 workers in the combined module
run; verified green in three consecutive combined runs plus a
TZ=America/New_York spot check.

Diff

findfamily/src/test/java/com/vayunmathur/findfamily/platform/FixCeilingAlarmTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FixCeilingAlarmTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FixCeilingAlarmTest.ktindex a4617a526d..69edd56e30 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FixCeilingAlarmTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FixCeilingAlarmTest.kt@@ -142,6 +142,13 @@ class FixCeilingAlarmTest {     @Test     fun everyCheckMovesTheAlarmToOneCeilingLater() {         service.updateFixCeiling(true)+        // The service's own heartbeat can fire a keep-alive tick while+        // Robolectric idles the looper during setup, consuming the+        // "never attempted" due-ness (lastForcedFixAttemptMs) before this+        // test's first tick — whether it does is pure scheduling, which+        // is why this only failed in loaded combined runs. Reset the+        // attempt bookkeeping so the first tick is deterministic.+        service.lastForcedFixAttemptMs = null         val first = now()         await(service.fixCeilingAlarmTick())         assertEquals(listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER), forcedCalls.toList())
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.ktindex b176d5cf2d..04b4aea13d 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt@@ -61,11 +61,15 @@ class FindFamilyViewModelDbTest {     private fun pump() = Shadows.shadowOf(Looper.getMainLooper()).idle()      private suspend fun awaitTrue(desc: String, timeoutMs: Long = 8_000, cond: () -> Boolean) {-        val dl = System.currentTimeMillis() + timeoutMs-        while (System.currentTimeMillis() < dl) {+        // Step counted: Robolectric's substituted clock can run ahead of+        // real time, expiring a wall-clock deadline before background+        // flow work lands on a loaded box.+        var steps = 0+        val maxSteps = (timeoutMs / 25).toInt()+        while (steps++ < maxSteps) {             pump()             if (cond()) return-            delay(40)+            try { Thread.sleep(25) } catch (_: InterruptedException) { }         }         throw AssertionError("timed out waiting for: $desc")     }@@ -86,8 +90,16 @@ class FindFamilyViewModelDbTest {             launchCollect(vm)         }         awaitTrue("connected users") { vm.connectedUsers.value.map { it.name }.containsAll(listOf("Alice", "Carol")) }+        // Each derived WhileSubscribed flow computes independently; on a+        // loaded box awaitingRequest/usersByLocationName can still hold+        // their initial empty values when connectedUsers lands, so await+        // each condition instead of asserting the first snapshot (the CI+        // failure was awaiting == [] for exactly this reason).+        awaitTrue("awaiting request users") { vm.awaitingRequestUsers.value.map { it.name } == listOf("Bob") }         assertEquals(listOf("Bob"), vm.awaitingRequestUsers.value.map { it.name })+        awaitTrue("users by id") { vm.usersById.value.values.any { it.name == "Bob" } }         assertEquals("Office", vm.usersById.value.values.first { it.name == "Bob" }.locationName)+        awaitTrue("users by location") { vm.usersByLocationName.value["Office"]?.sorted() == listOf("Bob", "Carol") }         assertEquals(listOf("Bob", "Carol"), vm.usersByLocationName.value["Office"]?.sorted())         awaitTrue("waypoints") { vm.waypoints.value.size == 1 }         // Repository one-shot sees the fix (same getLatest DAO query the VM flow wraps).
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.ktindex bcc52237ba..005b840d4b 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt@@ -240,7 +240,13 @@ class FindFamilyViewModelRealRepoTest {         await("connected projected") {             vm.connectedUsers.value.map { it.name }.containsAll(listOf("Alice", "Carol"))         }+        // Each derived flow projects independently; awaitingRequest and+        // usersById can still hold their initial empty values when the+        // connected projection lands, so await them too (the DbTest+        // sibling failed in CI for exactly this snapshot race).+        await("awaiting projected") { vm.awaitingRequestUsers.value.map { it.name } == listOf("Bob") }         assertEquals(listOf("Bob"), vm.awaitingRequestUsers.value.map { it.name })+        await("by-id projected") { vm.usersById.value[alice]?.name == "Alice" }         assertEquals("Alice", vm.usersById.value[alice]?.name)         vm.selectUser(alice)         await("history projected") { vm.locationHistory.value.size == 1 }