-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathSuspendAppTest.kt
More file actions
95 lines (84 loc) · 3.02 KB
/
Copy pathSuspendAppTest.kt
File metadata and controls
95 lines (84 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import io.kotest.inspectors.shouldForAtLeastOne
import io.kotest.inspectors.shouldForNone
import io.kotest.inspectors.shouldForOne
import io.kotest.matchers.collections.shouldBeIn
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldEndWith
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.time.Duration.Companion.seconds
abstract class SuspendAppTest : ProcessProvider {
@Test
fun delay() = runTest {
val (process, output) = execute("delay")
process.exitValue() shouldBe 0
output.shouldForOne { it.line shouldBe "resource clean complete" }
}
@Test
fun fail() = runTest {
val (process, output) = execute("fail")
process.exitValue() shouldBe 255
output.shouldForOne { it.line shouldBe "resource clean complete" }
.shouldForAtLeastOne { it.line shouldEndWith "IllegalStateException: BOOM!" }
}
@Test
fun exit() = runTest {
val (process, output) = execute("exit")
process.exitValue() shouldBe 42
output
.filter { it.source == "stdout" }
.shouldForNone { it.line shouldBe "resource clean complete" }
.last().line shouldBe "Running ExitProcess"
}
@Test
fun childFailure() = runTest {
val (process, output) = execute("childfail")
process.exitValue() shouldBe 255
output.shouldForOne { it.line shouldBe "resource clean complete" }
.shouldForAtLeastOne { it.line shouldEndWith "IllegalStateException: boom." }
}
@Test
fun exitApp() = runTest {
val (process, output) = execute("exitapp")
process.exitValue() shouldBe 42
output.shouldForOne { it.line shouldBe "resource clean complete" }
}
@Test
fun childExitApp() = runTest {
val (process, output) = execute("childexitapp")
process.exitValue() shouldBe 2
output.shouldForOne { it.line shouldBe "resource clean complete" }
}
@Test
fun childLaunchExitApp() = runTest {
val (process, output) = execute("childlaunchexitapp")
process.exitValue() shouldBe 24
output.shouldForOne { it.line shouldBe "resource clean complete" }
}
@Test
fun waitAndSignalSigterm() = waitAndSignal(Signal.SIGTERM)
@Test
fun waitAndSignalSigint() = waitAndSignal(Signal.SIGINT)
@Test
fun waitAndTimeout() = runTest {
val (process, output) = execute("timeout") {
delay(0.5.seconds)
sendSignal(Signal.SIGTERM)
}
// TODO: inconsistent exit codes across platforms, for now just check it's not a success
process.exitValue() shouldNotBe 0
output.shouldForAtLeastOne { it.line shouldContain "Timed out waiting for 5000 ms" }
.shouldForNone { it.line shouldContain "resource clean complete" }
}
private fun waitAndSignal(signal: Signal, mode: String = "wait") = runTest {
val (process, output) = execute(mode) {
delay(0.5.seconds)
sendSignal(signal)
}
process.exitValue() shouldBe signal.code + 128
output.shouldForOne { it.line shouldBe "resource clean complete" }
}
}