Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing the TestScope.coroutineContext to launchForTestingFromState/Start causes a crash #983

Open
0legg opened this issue Mar 31, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@0legg
Copy link
Contributor

0legg commented Mar 31, 2023

workflow.launchForTestingFromStateWith(..., context = testContext, ...) fails with

Test finished
java.util.concurrent.CancellationException: Test finished
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt$launchForTestingWith$2$1.invoke(WorkflowTestRuntime.kt:285)
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt.unwrapCancellationCause(WorkflowTestRuntime.kt:322)
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt.access$unwrapCancellationCause(WorkflowTestRuntime.kt:1)
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt$launchForTestingWith$2.invoke(WorkflowTestRuntime.kt:276)
	at com.squareup.workflow1.internal.util.UncaughtExceptionGuard.runRethrowingUncaught(UncaughtExceptionGuard.kt:32)
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt.launchForTestingWith(WorkflowTestRuntime.kt:275)
	at com.squareup.workflow1.testing.WorkflowTestRuntimeKt.launchForTestingFromStateWith(WorkflowTestRuntime.kt:210)

, but workflow.launchForTestingFromStateWith(..., context = testContext[CoroutineDispatcher.Key]!!, ...) succeed.

It may be connected with the way uncaughtExceptionHandler is set for workflow test runtime:

  val uncaughtExceptionHandler = CoroutineExceptionHandler { _, throwable ->
    exceptionGuard.reportUncaught(throwable)
  }
....
  val workflowScope = CoroutineScope(Unconfined + context + uncaughtExceptionHandler)
  val outputs = Channel<OutputT>(capacity = UNLIMITED)
  workflowScope.coroutineContext[Job]!!.invokeOnCompletion {
    outputs.close(it)
  }
@steve-the-edwards steve-the-edwards added the good first issue Good for newcomers label Jun 19, 2023
@steve-the-edwards steve-the-edwards removed their assignment Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants