Modern Apps git

← Modern-Apps.git

fooddelivery: make awaitNode step-counted instead of virtual-clock bounded

Commit
2fc47894677388a9870cb1333768a357236ea487
Author
Vayun Mathur <[email protected]>
When
2026-11-17 12:22 UTC (19 days ago)
Parents
4ff6945
CI failed FoodFlow4Test.dealsCompletedProgressCard and FoodFlow5Test.trackingPreparingSoonWithFarDueDate, both of which wait through the shared awaitNode helper.

awaitNode bounded its wait with System.currentTimeMillis, but each poll also calls idleFor(300ms), which advances Robolectric's substituted clock by at least that much per step. Fifteen wall-clock seconds therefore burned in roughly fifty steps and a few real seconds, while the fetches being awaited (AppInit warm-up plus Bites API calls on IO/Default dispatchers) need real time that a loaded CI box gives them slowly. The deadline could expire before the node it waited for was ever composed; unloaded, both tests pass.

The helper in both classes now counts 600 steps with a real Thread.sleep(50) per step, so the budget is a real duration and the condition (the node exists) is what ends the wait. Assertions unchanged.

Verified: FoodFlow4Test and FoodFlow5Test pass directly, and :fooddelivery:testDevUnitTest was green in two parallel all-module runs.

Diff

fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.ktindex 0e29c31aad..45ba253965 100644--- a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow4Test.kt@@ -55,9 +55,13 @@ class FoodFlow4Test {     )      private fun awaitNode(text: String, substring: Boolean = true) {-        val deadline = System.currentTimeMillis() + 15_000+        // Step-counted, not wall-clock: Robolectric's substituted clock+        // advances hundreds of ms per idleFor below, so a 15s deadline+        // burned in a few real seconds under load, before the IO fetch+        // it waits for had run. Each step sleeps real time instead.         var found = false-        while (System.currentTimeMillis() < deadline) {+        var step = 0+        while (step++ < 600) {             rule.mainClock.autoAdvance = false             rule.mainClock.advanceTimeBy(600L)             rule.mainClock.autoAdvance = true
fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt
diff --git a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.ktindex c6644149f6..50c06ee2e9 100644--- a/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt+++ b/fooddelivery/src/test/java/com/vayunmathur/fooddelivery/ui/FoodFlow5Test.kt@@ -55,9 +55,13 @@ class FoodFlow5Test {     }      private fun awaitNode(text: String, substring: Boolean = true) {-        val deadline = System.currentTimeMillis() + 15_000+        // Step-counted, not wall-clock: Robolectric's substituted clock+        // advances hundreds of ms per idleFor below, so a 15s deadline+        // burned in a few real seconds under load, before the IO fetch+        // it waits for had run. Each step sleeps real time instead.         var found = false-        while (System.currentTimeMillis() < deadline) {+        var step = 0+        while (step++ < 600) {             rule.mainClock.autoAdvance = false             rule.mainClock.advanceTimeBy(600L)             rule.mainClock.autoAdvance = true