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.
This commit is contained in:
austinried
2026-11-15 12:11:44 +00:00
parent b584944f07
commit 15f9a9f48d
@@ -17,8 +17,12 @@ fun awaitUntil(
predicate: () -> Boolean, predicate: () -> Boolean,
) { ) {
val deadline = System.nanoTime() + TEST_TIMEOUT_MS * 1_000_000 val deadline = System.nanoTime() + TEST_TIMEOUT_MS * 1_000_000
while (!predicate() && System.nanoTime() < deadline) Thread.sleep(10) var met = predicate()
if (predicate()) return 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 // 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 // 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. // stall is diagnosable from the CI log, which shows exception messages but not the test XML.