communicate: settle-wait in real time and pump the looper for RCS waits (1390 tests)
- Commit
1f044e998a71bcd5941d011ed81fe849a7ac0c14- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-15 22:47 UTC (20 days ago)
- Parents
c8edac8
signalPrefix_isStripped failed in CI with the persisted message null. The Signal and WhatsApp processor tests drain their event processors on Dispatchers.IO but polled for settlement with delays inside runTest, whose virtual clock burns the poll budget in near-zero real time; under CI load the processor had not run yet when the assertions read the DAOs. Run the settle polling on Dispatchers.Default so the budget is real time, in both SignalSlice2ProcessorTest and W5Slice1EventProcessorTest. Assertions unchanged. Also idle Robolectric's paused main looper inside RcsSlice3Pass2UiTest.waitForText: the RCS screens load through Dispatchers.Main and waitUntil alone does not run its queued resumes (observed as a 30s ComposeTimeout in the same module). Verified green 3x under TZ=America/New_York; TZ=UTC re-verified after this change (see final CI-like run).
Diff
communicate/src/test/java/com/vayunmathur/communicate/rcs/RcsSlice3Pass2UiTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/rcs/RcsSlice3Pass2UiTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/rcs/RcsSlice3Pass2UiTest.ktindex 020adadac8..c91b371cc0 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/rcs/RcsSlice3Pass2UiTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/rcs/RcsSlice3Pass2UiTest.kt@@ -65,7 +65,11 @@ class RcsSlice3Pass2UiTest { } private fun waitForText(text: String, timeoutMs: Long = 10_000) {+ // Idle Robolectric's paused main looper per poll: the screens load+ // through Dispatchers.Main, whose queued resumes waitUntil alone+ // does not run, so the text could sit unlanded past the timeout. rule.waitUntil(timeoutMs) {+ org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle() rule.onAllNodesWithText(text).fetchSemanticsNodes().isNotEmpty() } }
communicate/src/test/java/com/vayunmathur/communicate/signal/SignalSlice2ProcessorTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/signal/SignalSlice2ProcessorTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/signal/SignalSlice2ProcessorTest.ktindex b0fd0de2ab..cb840fbf3e 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/signal/SignalSlice2ProcessorTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/signal/SignalSlice2ProcessorTest.kt@@ -59,19 +59,23 @@ class SignalSlice2ProcessorTest { private suspend fun emit(e: SignalEvent) { events.emit(e)- var waited = 0- while (waited < 500 && !settled(e)) {- kotlinx.coroutines.delay(10)- waited++- }+ awaitSettled { settled(e) } } - /** Poll until [cond] holds (bounded); mirrors the WhatsApp slice's processor test. */+ /**+ * Poll until [cond] holds (bounded); mirrors the WhatsApp slice's+ * processor test. The wait runs on a real-time dispatcher: this class+ * uses runTest, whose virtual clock burns a delay budget instantly,+ * while the processor drains on Dispatchers.IO in real time — polling+ * on the test scheduler lost that race under load.+ */ private suspend fun awaitSettled(cond: suspend () -> Boolean) {- var waited = 0- while (waited < 500 && !cond()) {- kotlinx.coroutines.delay(10)- waited+++ kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) {+ var waited = 0+ while (waited < 500 && !cond()) {+ kotlinx.coroutines.delay(10)+ waited+++ } } }
communicate/src/test/java/com/vayunmathur/communicate/whatsapp/W5Slice1EventProcessorTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/W5Slice1EventProcessorTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/W5Slice1EventProcessorTest.ktindex 3373b79f75..d2f4ebcd71 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/W5Slice1EventProcessorTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/W5Slice1EventProcessorTest.kt@@ -55,20 +55,23 @@ class W5Slice1EventProcessorTest { private suspend fun emit(e: WhatsAppEvent) { events.emit(e)- // start() collects on Dispatchers.IO; poll until the row lands (bounded).- var waited = 0- while (waited < 200 && !settled(e)) {- kotlinx.coroutines.delay(10)- waited++- }+ awaitSettled { settled(e) } } - /** Poll until [cond] holds (bounded); fails the test on timeout via empty result. */+ /**+ * Poll until [cond] holds (bounded). The wait runs on a real-time+ * dispatcher: these tests use runTest, whose virtual clock burns a+ * delay budget instantly, while the processor drains on+ * Dispatchers.IO in real time — polling on the test scheduler lost+ * that race under load.+ */ private suspend fun awaitSettled(cond: suspend () -> Boolean) {- var waited = 0- while (waited < 200 && !cond()) {- kotlinx.coroutines.delay(10)- waited+++ kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) {+ var waited = 0+ while (waited < 200 && !cond()) {+ kotlinx.coroutines.delay(10)+ waited+++ } } }