From 15f9a9f48d7b1f3964df8c0fdeaac20e53b5ea68 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:13:18 +0000 Subject: [PATCH] test: evaluate awaitUntil's predicate once per iteration awaitUntil checked the predicate again when leaving the loop. A predicate that is only transiently true, such as one that an in-flight edit satisfies before the edit lands, could end the loop on its true result and then fail the second check, reporting a timeout that had not elapsed. --- app/src/test/kotlin/com/subtracks/TestSupport.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/test/kotlin/com/subtracks/TestSupport.kt b/app/src/test/kotlin/com/subtracks/TestSupport.kt index 9e680ade..132ed103 100644 --- a/app/src/test/kotlin/com/subtracks/TestSupport.kt +++ b/app/src/test/kotlin/com/subtracks/TestSupport.kt @@ -17,8 +17,12 @@ fun awaitUntil( predicate: () -> Boolean, ) { val deadline = System.nanoTime() + TEST_TIMEOUT_MS * 1_000_000 - while (!predicate() && System.nanoTime() < deadline) Thread.sleep(10) - if (predicate()) return + var met = predicate() + while (!met && System.nanoTime() < deadline) { + Thread.sleep(10) + met = predicate() + } + if (met) return // A wall-clock wait that expires means something stalled rather than ran slow: the suite // finishes in milliseconds per test. Print every thread's stack in the failure message so the // stall is diagnosable from the CI log, which shows exception messages but not the test XML.