1 /* 2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.exceptions 6 7 import kotlinx.coroutines.* 8 import kotlinx.coroutines.selects.* 9 import org.junit.* 10 import org.junit.rules.* 11 12 class StackTraceRecoverySelectTest : TestBase() { 13 14 @get:Rule 15 val name = TestName() 16 17 @Test testSelectJoinnull18 fun testSelectJoin() = runTest { 19 expect(1) 20 val result = runCatching { doSelect() } 21 expect(3) 22 verifyStackTrace("select/${name.methodName}", result.exceptionOrNull()!!) 23 finish(4) 24 } 25 doSelectnull26 private suspend fun doSelect(): Int { 27 val job = CompletableDeferred(Unit) 28 return select { 29 job.onJoin { 30 yield() // Hide the stackstrace 31 expect(2) 32 throw RecoverableTestException() 33 } 34 } 35 } 36 37 @Test <lambda>null38 fun testSelectCompletedAwait() = runTest { 39 val deferred = CompletableDeferred<Unit>() 40 deferred.completeExceptionally(RecoverableTestException()) 41 val result = runCatching { doSelectAwait(deferred) } 42 verifyStackTrace("select/${name.methodName}", result.exceptionOrNull()!!) 43 } 44 doSelectAwaitnull45 private suspend fun doSelectAwait(deferred: Deferred<Unit>): Int { 46 return select { 47 deferred.onAwait { 48 yield() // Hide the frame 49 42 50 } 51 } 52 } 53 } 54