Modern Apps git

← Modern-Apps.git

health: wait settle() in real time for recipe save test (#tests)

Commit
b94b3985cfa15dad1f9b8f617ac3e91cb96e1eb1
Author
Vayun Mathur <[email protected]>
When
2026-11-16 18:25 UTC (20 days ago)
Parents
628780b
The recipe load/save test's settle() loop ran 200 x delay(5)
inside runTest, where delays are virtual: the whole budget
burned instantly while the real IO write was still in flight
on the loaded CI box, and the assertions then read a stale
database. settle() now polls in real time (step-counted with
the main looper pumped), so `done` genuinely implies the
Room writes have landed.

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

health/src/test/java/com/vayunmathur/health/util/HealthViewModelTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/util/HealthViewModelTest.kt b/health/src/test/java/com/vayunmathur/health/util/HealthViewModelTest.ktindex 8bf44559fc..b3d44d9146 100644--- a/health/src/test/java/com/vayunmathur/health/util/HealthViewModelTest.kt+++ b/health/src/test/java/com/vayunmathur/health/util/HealthViewModelTest.kt@@ -67,10 +67,15 @@ class HealthViewModelTest {     }      private suspend fun settle(cond: suspend () -> Boolean) {-        repeat(200) {+        // Step counted in real time (parkNanos), not runTest virtual time:+        // the old 200 x delay(5) loop burned its whole budget instantly in+        // virtual time while the real IO write was still in flight on a+        // loaded CI box, then asserted against a stale database.+        var steps = 0+        while (steps++ < 800) {             Shadows.shadowOf(Looper.getMainLooper()).idle()             if (cond()) return-            delay(5)+            try { Thread.sleep(25) } catch (_: InterruptedException) { }         }     }