health: poll draft-load settles in real time instead of iterations
- Commit
bf2e9a698a77215e6f551c28a80b1ba5f76fa698- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 12:21 UTC (19 days ago)
- Parents
e8faa5b
CI failed two vaccination tests: MirrorAndDraftLoadTest's starting-a-vaccination-draft-loads-entry and VaccinationSavePathsTest's removing-a-saved-attachment-on-edit-deletes-file-and-row.
Both awaited MedicalViewModel work through settle/settleUntil helpers bounded as repeat(200) { idle the main looper; delay(5) }. Inside runTest that delay is virtual time, so the 200 iterations burned through in milliseconds of real time, while the work being waited for (a viewModelScope load on Main plus Room IO) needs real time on a loaded box. The helpers gave up before the draft loaded and the following assertions failed; unloaded, the same tests pass.
The helpers now poll the same conditions against a real-time deadline, idling the paused Robolectric main looper and sleeping real time between polls, the pattern EmlViewerSuccessTest already uses. Assertions are unchanged.
Verified: the two test classes pass directly, and :health:testDevUnitTest was green in two parallel all-module runs.Diff
health/src/test/java/com/vayunmathur/health/platform/MirrorAndDraftLoadTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/platform/MirrorAndDraftLoadTest.kt b/health/src/test/java/com/vayunmathur/health/platform/MirrorAndDraftLoadTest.ktindex 6a0604915b..efbd44fa25 100644--- a/health/src/test/java/com/vayunmathur/health/platform/MirrorAndDraftLoadTest.kt+++ b/health/src/test/java/com/vayunmathur/health/platform/MirrorAndDraftLoadTest.kt@@ -54,10 +54,15 @@ class MirrorAndDraftLoadTest { } private suspend fun settleUntil(cond: () -> Boolean) {- repeat(200) {+ // Poll in real time, idling the paused main looper so the+ // ViewModel's Main-thread work can land: a fixed iteration count+ // with a (virtual-time) delay burned through its budget in+ // milliseconds under CI load, before the Room IO it waited on ran.+ val deadline = System.currentTimeMillis() + 15_000+ while (System.currentTimeMillis() < deadline) { Shadows.shadowOf(Looper.getMainLooper()).idle() if (cond()) return- kotlinx.coroutines.delay(5)+ Thread.sleep(10) } }
health/src/test/java/com/vayunmathur/health/platform/VaccinationSavePathsTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/platform/VaccinationSavePathsTest.kt b/health/src/test/java/com/vayunmathur/health/platform/VaccinationSavePathsTest.ktindex d68417a531..044078eaf0 100644--- a/health/src/test/java/com/vayunmathur/health/platform/VaccinationSavePathsTest.kt+++ b/health/src/test/java/com/vayunmathur/health/platform/VaccinationSavePathsTest.kt@@ -49,10 +49,15 @@ class VaccinationSavePathsTest { private fun vm(): MedicalViewModel = MedicalViewModel(context, repo()) private suspend fun settle(cond: suspend () -> Boolean) {- repeat(200) {+ // Poll in real time, idling the paused main looper so the+ // ViewModel's Main-thread work can land: a fixed iteration count+ // with a (virtual-time) delay burned through its budget in+ // milliseconds under CI load, before the Room IO it waited on ran.+ val deadline = System.currentTimeMillis() + 15_000+ while (System.currentTimeMillis() < deadline) { Shadows.shadowOf(Looper.getMainLooper()).idle() if (cond()) return- kotlinx.coroutines.delay(5)+ Thread.sleep(10) } }