File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
kotlinx-coroutines-core/common/test Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments