Skip to content

Commit 8e425e1

Browse files
authored
Change timed test to use measureTimedValue instead of manually calculating time to see if it prevents flakyness (#237)
1 parent bfc7d8f commit 8e425e1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

arrow-libs/fx/arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/BracketCaseTest.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import io.kotest.property.Arb
66
import io.kotest.property.arbitrary.int
77
import io.kotest.property.arbitrary.long
88
import io.kotest.property.checkAll
9+
import kotlin.time.ExperimentalTime
10+
import kotlin.time.measureTimedValue
911

12+
@ExperimentalTime
1013
class BracketCaseTest : ArrowFxSpec(spec = {
1114

1215
"Uncancellable back pressures timeoutOrNull" {
1316
checkAll(Arb.long(10, 100), Arb.long(300, 400)) { a, b ->
14-
val start = System.currentTimeMillis()
15-
16-
val n = timeOutOrNull(a.milliseconds) {
17-
uncancellable { sleep(b.milliseconds) }
17+
val (n, duration) = measureTimedValue {
18+
timeOutOrNull(a.milliseconds) {
19+
uncancellable { sleep(b.milliseconds) }
20+
}
1821
}
1922

20-
val end = System.currentTimeMillis()
21-
2223
n shouldBe null // timed-out so should be null
23-
require((end - start) >= b) {
24-
"Should've taken longer than $b milliseconds, but took ${end - start}ms. (start=$start, end=$end)"
24+
require((duration.inMilliseconds) >= b) {
25+
"Should've taken longer than $b milliseconds, but took $duration"
2526
}
2627
}
2728
}

0 commit comments

Comments
 (0)