Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Change timed test to use measureTimedValue instead of manually calcul…
Browse files Browse the repository at this point in the history
…ating time to see if it prevents flakyness (#237)
  • Loading branch information
aballano authored Jul 30, 2020
1 parent 561aef3 commit 92f437d
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.long
import io.kotest.property.checkAll
import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue

@ExperimentalTime
class BracketCaseTest : ArrowFxSpec(spec = {

"Uncancellable back pressures timeoutOrNull" {
checkAll(Arb.long(10, 100), Arb.long(300, 400)) { a, b ->
val start = System.currentTimeMillis()

val n = timeOutOrNull(a.milliseconds) {
uncancellable { sleep(b.milliseconds) }
val (n, duration) = measureTimedValue {
timeOutOrNull(a.milliseconds) {
uncancellable { sleep(b.milliseconds) }
}
}

val end = System.currentTimeMillis()

n shouldBe null // timed-out so should be null
require((end - start) >= b) {
"Should've taken longer than $b milliseconds, but took ${end - start}ms. (start=$start, end=$end)"
require((duration.inMilliseconds) >= b) {
"Should've taken longer than $b milliseconds, but took $duration"
}
}
}
Expand Down

0 comments on commit 92f437d

Please sign in to comment.