Skip to content

Commit b02ee06

Browse files
authored
Introduce tests that cover behaviour explained in #4457 (#4509)
1 parent 560ea27 commit b02ee06

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package kotlinx.coroutines
2+
3+
import kotlinx.coroutines.testing.TestBase
4+
import kotlin.coroutines.EmptyCoroutineContext
5+
import kotlin.test.Test
6+
import kotlin.test.assertTrue
7+
8+
// See https://github.com/Kotlin/kotlinx.coroutines/issues/4457
9+
class ScopedBuildersCancelledStartTest : TestBase() {
10+
11+
@Test
12+
fun testCancelledCoroutineScope() = runTest(expected = { it is CancellationException }) {
13+
cancel()
14+
coroutineScope {
15+
finish(1)
16+
}
17+
expectUnreached()
18+
}
19+
20+
@Test
21+
fun testCancelledSupervisorScope() = runTest(expected = { it is CancellationException }) {
22+
cancel()
23+
supervisorScope {
24+
finish(1)
25+
}
26+
expectUnreached()
27+
}
28+
29+
@Test
30+
fun testCancelledWithTimeout() = runTest(expected = { it is CancellationException }) {
31+
cancel()
32+
withTimeout(Long.MAX_VALUE) {
33+
finish(1)
34+
}
35+
expectUnreached()
36+
}
37+
38+
@Test
39+
fun testWithContext() = runTest(expected = { it is CancellationException }) {
40+
cancel()
41+
withContext(EmptyCoroutineContext) {
42+
assertTrue(coroutineContext.job.isCancelled)
43+
expect(1)
44+
}
45+
finish(2)
46+
}
47+
48+
@Test
49+
fun testWithContextWithDispatcher() = runTest(expected = { it is CancellationException }) {
50+
cancel()
51+
withContext(Dispatchers.Unconfined) {
52+
assertTrue(coroutineContext.job.isCancelled)
53+
expect(1)
54+
}
55+
finish(2)
56+
}
57+
}

0 commit comments

Comments
 (0)