Skip to content

Commit

Permalink
Set next snapshot (#3669) (#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Sep 2, 2023
1 parent c25055f commit 5f003fa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TimeoutTest : FunSpec() {
timeout = 10000.milliseconds,
invocations = 1
) {
delay(50)
delay(1.hours)
}

test("a testcase timeout should apply if the cumulative sum of invocations is greater than the timeout value").config(
Expand Down
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)
}
}
}

0 comments on commit 5f003fa

Please sign in to comment.