• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.debug
6 
7 import kotlinx.coroutines.*
8 import org.junit.*
9 import kotlin.coroutines.*
10 
11 class ScopedBuildersTest : DebugTestBase() {
12 
13     @Test
<lambda>null14     fun testNestedScopes() = runBlocking {
15         val job = launch { doInScope() }
16         yield()
17         yield()
18         verifyDump(
19             "Coroutine \"coroutine#1\":BlockingCoroutine{Active}@16612a51, state: RUNNING\n" +
20              "\tat _COROUTINE._CREATION._(CoroutineDebugging.kt)\n" +
21                 "\tat kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:116)\n",
22 
23             "Coroutine \"coroutine#2\":StandaloneCoroutine{Active}@6b53e23f, state: SUSPENDED\n" +
24                 "\tat kotlinx.coroutines.debug.ScopedBuildersTest\$doWithContext\$2.invokeSuspend(ScopedBuildersTest.kt:49)\n" +
25                 "\tat kotlinx.coroutines.debug.ScopedBuildersTest.doWithContext(ScopedBuildersTest.kt:47)\n" +
26                 "\tat kotlinx.coroutines.debug.ScopedBuildersTest\$doInScope\$2.invokeSuspend(ScopedBuildersTest.kt:41)\n" +
27                 "\tat kotlinx.coroutines.debug.ScopedBuildersTest\$testNestedScopes\$1\$job\$1.invokeSuspend(ScopedBuildersTest.kt:30)\n" +
28             "\tat _COROUTINE._CREATION._(CoroutineDebugging.kt)\n" +
29                 "\tat kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:116)")
30         job.cancelAndJoin()
31         finish(4)
32     }
33 
<lambda>null34     private suspend fun doInScope() = coroutineScope {
35         expect(1)
36         doWithContext()
37         expectUnreached()
38     }
39 
doWithContextnull40     private suspend fun doWithContext() {
41         expect(2)
42         withContext(wrapperDispatcher(coroutineContext)) {
43             expect(3)
44             delay(Long.MAX_VALUE)
45         }
46         expectUnreached()
47     }
48 }
49