/
CancellationGuideTest.kt
98 lines (88 loc) · 3.11 KB
/
CancellationGuideTest.kt
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
96
97
98
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
// This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.test
import kotlinx.coroutines.knit.*
import org.junit.Test
class CancellationGuideTest {
@Test
fun testExampleCancel01() {
test("ExampleCancel01") { kotlinx.coroutines.guide.exampleCancel01.main() }.verifyLines(
"job: I'm sleeping 0 ...",
"job: I'm sleeping 1 ...",
"job: I'm sleeping 2 ...",
"main: I'm tired of waiting!",
"main: Now I can quit."
)
}
@Test
fun testExampleCancel02() {
test("ExampleCancel02") { kotlinx.coroutines.guide.exampleCancel02.main() }.verifyLines(
"job: I'm sleeping 0 ...",
"job: I'm sleeping 1 ...",
"job: I'm sleeping 2 ...",
"main: I'm tired of waiting!",
"job: I'm sleeping 3 ...",
"job: I'm sleeping 4 ...",
"main: Now I can quit."
)
}
@Test
fun testExampleCancel04() {
test("ExampleCancel04") { kotlinx.coroutines.guide.exampleCancel04.main() }.verifyLines(
"job: I'm sleeping 0 ...",
"job: I'm sleeping 1 ...",
"job: I'm sleeping 2 ...",
"main: I'm tired of waiting!",
"main: Now I can quit."
)
}
@Test
fun testExampleCancel05() {
test("ExampleCancel05") { kotlinx.coroutines.guide.exampleCancel05.main() }.verifyLines(
"job: I'm sleeping 0 ...",
"job: I'm sleeping 1 ...",
"job: I'm sleeping 2 ...",
"main: I'm tired of waiting!",
"job: I'm running finally",
"main: Now I can quit."
)
}
@Test
fun testExampleCancel06() {
test("ExampleCancel06") { kotlinx.coroutines.guide.exampleCancel06.main() }.verifyLines(
"job: I'm sleeping 0 ...",
"job: I'm sleeping 1 ...",
"job: I'm sleeping 2 ...",
"main: I'm tired of waiting!",
"job: I'm running finally",
"job: And I've just delayed for 1 sec because I'm non-cancellable",
"main: Now I can quit."
)
}
@Test
fun testExampleCancel07() {
test("ExampleCancel07") { kotlinx.coroutines.guide.exampleCancel07.main() }.verifyLinesStartWith(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
"Exception in thread \"main\" kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1300 ms"
)
}
@Test
fun testExampleCancel08() {
test("ExampleCancel08") { kotlinx.coroutines.guide.exampleCancel08.main() }.verifyLines(
"I'm sleeping 0 ...",
"I'm sleeping 1 ...",
"I'm sleeping 2 ...",
"Result is null"
)
}
@Test
fun testExampleCancel10() {
test("ExampleCancel10") { kotlinx.coroutines.guide.exampleCancel10.main() }.verifyLines(
"0"
)
}
}