-
Notifications
You must be signed in to change notification settings - Fork 688
Description
Using Kotest 5.8.1
, the following test
class MyTestClass {
@Test
fun myTestMethod() = runTest {
eventually {
error("Whoops!")
}
}
}
(running in JUnit 4 - Android project)
immediately fails with
java.lang.AssertionError: Block failed after 0ms; attempted 0 time(s)
The test block is never run, and the output is really just the above, giving no further details about what went wrong.
I've dug into this and believe the issue is that the duration
of the default EventuallyConfig
is set to INFINITE
:
Line 118 in 4ad8070
var duration: Duration = Duration.INFINITE |
which is then added to the start time:
Line 208 in 4ad8070
val end = start + config.duration.inWholeMilliseconds |
which results in an overflow, I believe. The result is that the check against the end time is immediately failing
Line 245 in 4ad8070
fun hasAttemptsRemaining() = timeInMillis() < end && iterations < config.retries |
While I initially wanted to raise this as a documentation issue only, I do wonder whether a duration
of INFINITE
should be handled specifically to mean "retry forever". Currently it basically results in "attempt not even once". To clarify: While the default value could simply be changed, I'm instead suggesting that EventuallyControl
should be changed to allow retrying forever.