Last active
March 3, 2019 19:41
-
-
Save Groostav/f8ef01ed830c14c394ac5b992d981aa1 to your computer and use it in GitHub Desktop.
trying to use Undispatched to clean up stack traces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//short form | |
java.lang.Exception | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$consumer$1.invokeSuspend(KotlinTests.kt:521) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1$1.invokeSuspend(KotlinTests.kt:514) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1$1.invoke(KotlinTests.kt) | |
at groostav.kotlinx.exec.KotlinTests.hardpoint(KotlinTests.kt:544) //BINGO!!! | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1.invokeSuspend(KotlinTests.kt:513) | |
//long form | |
java.lang.Exception | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$consumer$1.invokeSuspend(KotlinTests.kt:521) | |
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) | |
at kotlinx.coroutines.ResumeModeKt.resumeMode(ResumeMode.kt:67) | |
at kotlinx.coroutines.DispatchedKt.resume(Dispatched.kt:275) | |
at kotlinx.coroutines.UndispatchedEventLoop.resumeUndispatched(Dispatched.kt:56) | |
at kotlinx.coroutines.DispatchedKt.dispatch(Dispatched.kt:261) | |
at kotlinx.coroutines.AbstractContinuation.dispatchResume(AbstractContinuation.kt:182) | |
at kotlinx.coroutines.AbstractContinuation.completeStateUpdate(AbstractContinuation.kt:250) | |
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuation.kt:260) | |
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:909) | |
at kotlinx.coroutines.channels.AbstractSendChannel.offerInternal(AbstractChannel.kt:52) | |
at kotlinx.coroutines.channels.AbstractSendChannel.offer(AbstractChannel.kt:174) | |
at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:168) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1$1.invokeSuspend(KotlinTests.kt:514) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1$1.invoke(KotlinTests.kt) | |
at groostav.kotlinx.exec.KotlinTests.hardpoint(KotlinTests.kt:544) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$producer$1.invokeSuspend(KotlinTests.kt:513) | |
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) | |
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236) | |
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594) | |
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60) | |
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test fun `when using a rendezvous channel can see through to caller if configured`() = runBlocking{ | |
val channel = Channel<String>(RENDEZVOUS) | |
var exception: Exception? = null | |
val producer = GlobalScope.launch(Dispatchers.IO){ | |
hardpoint { | |
channel.send("hello!") | |
} | |
} | |
val consumer = GlobalScope.launch(Dispatchers.Unconfined){ | |
val next = channel.receive() | |
exception = Exception("blam!!") | |
} | |
consumer.join() | |
producer.join() | |
assertTrue( | |
hardpointFrame in (exception?.stackTrace ?: emptyArray<StackTraceElement>()), | |
"expected \n$hardpointFrame\nin\n${exception?.stackTrace?.joinToString("\n at ")}" | |
) | |
} | |
var hardpointFrame: StackTraceElement? = null | |
private suspend fun <R> hardpoint(block: suspend() -> R){ | |
if(hardpointFrame == null){ | |
hardpointFrame = StackWalker.getInstance().walk { it.findFirst() }.orElse(null)?.toStackTraceElement() | |
} | |
block() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//short form | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$consumer$1.invokeSuspend(KotlinTests.kt:521) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1.invokeSuspend(KotlinTests.kt:518) | |
at groostav.kotlinx.exec.KotlinTests.when using a rendezvous channel can see through to caller if configured(KotlinTests.kt:507) | |
//long form | |
java.lang.Exception | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1$consumer$1.invokeSuspend(KotlinTests.kt:521) | |
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) | |
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:316) | |
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:23) | |
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109) | |
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:160) | |
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54) | |
at kotlinx.coroutines.BuildersKt.launch(Unknown Source) | |
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47) | |
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source) | |
at groostav.kotlinx.exec.KotlinTests$when using a rendezvous channel can see through to caller if configured$1.invokeSuspend(KotlinTests.kt:518) | |
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) | |
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236) | |
at kotlinx.coroutines.EventLoopBase.processNextEvent(EventLoop.kt:123) | |
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:69) | |
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:45) | |
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source) | |
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:35) | |
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source) | |
at groostav.kotlinx.exec.KotlinTests.when using a rendezvous channel can see through to caller if configured(KotlinTests.kt:507) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment