mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-16 01:00:17 +01:00
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:
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user