Modern Apps git

← Modern-Apps.git

communicate: make the raw-socket test await step-counted

Commit
c453811918fccfeb59e766bc96dea274a4889fae
Author
Vayun Mathur <[email protected]>
When
2026-11-17 12:22 UTC (19 days ago)
Parents
7825901
CI failed Y2SignalSocketRegTest's raw-websocket-request-response-push-and-disconnect. Every stage of that test (connect, request/response, pushed message, disconnect state) waits through the local await helper, which bounded its 12 seconds by System.currentTimeMillis. That is Robolectric's substituted clock, which does not track real time while the test thread sleeps, so the budget could expire while the real socket threads (the in-process RFC6455 server, the client's IO dispatchers) were still landing their work under load; unloaded the test passes. The lint wave's only SignalSocket change (normalising to the application context) is a no-op for this test, whose context already is the application.

await now derives a step count from the caller's budget and sleeps real time per step, keeping a final condition check, so the duration it waits is real. No assertion changed and the socket timeouts inside the test are untouched.

Verified: Y2SignalSocketRegTest passes directly (about five minutes), and :communicate:testDevUnitTest was green in two parallel all-module runs.

Diff

communicate/src/test/java/com/vayunmathur/communicate/signal/Y2SignalSocketRegTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/signal/Y2SignalSocketRegTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/signal/Y2SignalSocketRegTest.ktindex da4c3b9b28..a9a0028460 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/signal/Y2SignalSocketRegTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/signal/Y2SignalSocketRegTest.kt@@ -224,11 +224,17 @@ class Y2SignalSocketRegTest {     }      private fun await(label: String, timeoutMs: Long = 12_000, cond: () -> Boolean) {-        val deadline = System.currentTimeMillis() + timeoutMs-        while (System.currentTimeMillis() < deadline) {+        // Step-counted from the caller's budget, not wall-clock:+        // Robolectric's substituted clock can run ahead of real time, so+        // a currentTimeMillis deadline expired under CI load while the+        // socket work it waited for (real threads) was still landing.+        // Each step sleeps real time, so the budget is a real duration.+        var steps = (timeoutMs / 20).toInt()+        while (steps-- > 0) {             if (cond()) return             Thread.sleep(20)         }+        if (cond()) return         error("timeout $label")     }