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

Tweak Bracket test #237

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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