forked from kotest/kotest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix timeout detection when withTimeout wraps a blocking job (kotest#3675
) * Fix timeout detection when withTimeout wraps a blocking job This is a workaround for kotlinx.coroutines/issues/3875. Fixes kotest#3672 * Add timeout tests --------- Co-authored-by: Sam <sam@sksamuel.com>
- Loading branch information
Showing
3 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...rk/kotest-framework-engine/src/jvmTest/kotlin/io/kotest/engine/concurrency/TimeoutTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.kotest.engine.concurrency | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.FunSpec | ||
import kotlinx.coroutines.TimeoutCancellationException | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withTimeout | ||
|
||
class TimeoutTest : FunSpec({ | ||
test("detection with blocking job") { | ||
shouldThrow<TimeoutCancellationException> { | ||
withTimeout(50) { | ||
launch { | ||
Thread.sleep(100) | ||
} | ||
} | ||
println("no timeout detected") | ||
} | ||
} | ||
|
||
test("detection with non-blocking job") { | ||
shouldThrow<TimeoutCancellationException> { | ||
withTimeout(50) { | ||
launch { | ||
delay(100) | ||
} | ||
} | ||
println("no timeout detected") | ||
} | ||
} | ||
}) |