1 /* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 package kotlinx.coroutines.debug 5 6 import kotlinx.coroutines.* 7 import org.junit.* 8 import org.junit.Test 9 import kotlin.test.* 10 11 class DumpWithoutCreationStackTraceTest : DebugTestBase() { 12 @Before setUpnull13 override fun setUp() { 14 super.setUp() 15 DebugProbes.enableCreationStackTraces = false 16 } 17 18 @Test <lambda>null19 fun testCoroutinesDump() = runTest { 20 val deferred = createActiveDeferred() 21 yield() 22 verifyDump( 23 "Coroutine \"coroutine#1\":BlockingCoroutine{Active}@70d1cb56, state: RUNNING\n" + 24 "\tat java.lang.Thread.getStackTrace(Thread.java)\n" + 25 "\tat kotlinx.coroutines.debug.internal.DebugProbesImpl.enhanceStackTraceWithThreadDumpImpl(DebugProbesImpl.kt)\n" + 26 "\tat kotlinx.coroutines.debug.internal.DebugProbesImpl.dumpCoroutinesSynchronized(DebugProbesImpl.kt)\n" + 27 "\tat kotlinx.coroutines.debug.internal.DebugProbesImpl.dumpCoroutines(DebugProbesImpl.kt)", 28 29 "Coroutine \"coroutine#2\":DeferredCoroutine{Active}@383fa309, state: SUSPENDED\n" + 30 "\tat kotlinx.coroutines.debug.DumpWithoutCreationStackTraceTest\$createActiveDeferred\$1.invokeSuspend(DumpWithoutCreationStackTraceTest.kt)" 31 ) 32 deferred.cancelAndJoin() 33 } 34 35 <lambda>null36 private fun CoroutineScope.createActiveDeferred(): Deferred<*> = async { 37 suspendingMethod() 38 assertTrue(true) 39 } 40 suspendingMethodnull41 private suspend fun suspendingMethod() { 42 delay(Long.MAX_VALUE) 43 } 44 } 45