Is there a good way to enforce a matcher is true...within some timeout? I'm trying to write tests for some ktor websocket code and I have to use a real server (there's no websocket client test harness) so I need some timing tolerances. I was thinking some helper function which could wrap a matcher call, like:
Copy code
within (5.milliseconds) {
someField shouldBe someValue
}
bbaldino
05/28/2020, 6:47 PM
I'm playing with:
Copy code
private suspend fun within(timeout: Duration, block: () -> Unit) {
withTimeout(timeout.toMillis()) {
while (true) {
try {
block()
break
} catch (t: Throwable) {
// Test every 5 ms
delay(5)
}
}
}
}
but this weirdly seems to make the test fail instantly, complaining
Test did not completed within 600000ms
bbaldino
05/28/2020, 6:47 PM
AH...it's firing the same exceptiona s the timeout does