-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
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
68 changes: 68 additions & 0 deletions
68
...rk-engine/src/jvmTest/kotlin/com/sksamuel/kotest/engine/test/timeout/EngineTimeoutTest.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,68 @@ | ||
package com.sksamuel.kotest.engine.test.timeout | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.engine.TestEngineLauncher | ||
import io.kotest.engine.listener.CollectingTestEngineListener | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlin.time.Duration.Companion.hours | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
class EngineTimeoutTest : FunSpec() { | ||
init { | ||
|
||
test("timeouts should be applied by the engine to suspend delays") { | ||
val collector = CollectingTestEngineListener() | ||
TestEngineLauncher(collector) | ||
.withClasses(DannyDelay::class) | ||
.launch() | ||
collector.names shouldBe listOf("a") | ||
collector.result("a")!!.errorOrNull!!.message!! shouldBe "Test 'a' did not complete within 1ms" | ||
} | ||
|
||
test("timeouts should be applied by the engine to suspend inside launched coroutines") { | ||
val collector = CollectingTestEngineListener() | ||
TestEngineLauncher(collector) | ||
.withClasses(LarryLauncher::class) | ||
.launch() | ||
collector.names shouldBe listOf("a") | ||
collector.result("a")!!.errorOrNull!!.message!! shouldBe "Test 'a' did not complete within 1ms" | ||
} | ||
|
||
test("timeouts should be applied by the engine to blocked threads") { | ||
val collector = CollectingTestEngineListener() | ||
TestEngineLauncher(collector) | ||
.withClasses(BillyBlocked::class) | ||
.launch() | ||
collector.names shouldBe listOf("a") | ||
collector.result("a")!!.errorOrNull!!.message!! shouldBe "sleep interrupted" | ||
} | ||
} | ||
} | ||
|
||
private class DannyDelay : FunSpec() { | ||
init { | ||
test("a").config(timeout = 1.milliseconds) { | ||
delay(24.hours) | ||
} | ||
} | ||
} | ||
|
||
private class LarryLauncher : FunSpec() { | ||
init { | ||
test("a").config(timeout = 1.milliseconds) { | ||
launch { | ||
delay(24.hours) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private class BillyBlocked : FunSpec() { | ||
init { | ||
test("a").config(timeout = 1.milliseconds, blockingTest = true) { | ||
Thread.sleep(1_000_000) | ||
} | ||
} | ||
} |