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

Make the context used to start workers configurable for tests. #940

Merged
merged 1 commit into from Feb 6, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

@zach-klippenstein zach-klippenstein commented Feb 5, 2020

This is helpful for tests that need to be able to control time.

This functionality was covered by the test's dispatcher, but since #851 changed the dispatcher used for workers, we need to be able to configure workers' contexts separately.

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/worker-test-context branch 3 times, most recently from 653b847 to 6c6adda Compare February 6, 2020 00:41
@zach-klippenstein zach-klippenstein changed the title WIP Make the context used to start workers configurable for tests. Make the context used to start workers configurable for tests. Feb 6, 2020
@zach-klippenstein zach-klippenstein added the bug Something isn't working label Feb 6, 2020
@zach-klippenstein zach-klippenstein added this to Needs review in Workflow (Kotlin) via automation Feb 6, 2020
This is helpful for tests that need to be able to control time.

This functionality was covered by the test's dispatcher, but since #851
changed the dispatcher used for workers, we need to be able to configure
workers' contexts separately.
@zach-klippenstein zach-klippenstein added this to the kotlin v0.23.2 milestone Feb 6, 2020
@zach-klippenstein zach-klippenstein marked this pull request as ready for review February 6, 2020 00:43
): CoroutineScope = this + CoroutineName(worker.debugName(key)) + Unconfined
key: String,
workerContext: CoroutineContext
): CoroutineScope = this + CoroutineName(worker.debugName(key)) + Unconfined + workerContext
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see what you meant when you were describing CouroutineScope at your talk.

@zach-klippenstein zach-klippenstein merged commit 5e0e4be into release-v0.23.x Feb 6, 2020
Workflow (Kotlin) automation moved this from Needs review to Done Feb 6, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/worker-test-context branch February 6, 2020 19:00
zach-klippenstein added a commit that referenced this pull request Feb 6, 2020
This is an enhancement to #940 that gives more reasonable behavior. The context
parameter to the test methods are primarily used to pass in test dispatchers, and
those dispatchers often really only need to be used for workers.

Since I don't know of a use case for specifying context separately just for workers,
this also removes the `WorkflowTestParams.workerContext` property.
zach-klippenstein added a commit that referenced this pull request Feb 6, 2020
This is an enhancement to #940 that gives more reasonable behavior. The context
parameter to the test methods are primarily used to pass in test dispatchers, and
those dispatchers often really only need to be used for workers.

Since I don't know of a use case for specifying context separately just for workers,
this also removes the `WorkflowTestParams.workerContext` property.
zach-klippenstein added a commit that referenced this pull request Feb 6, 2020
This is an enhancement to #940 that gives more reasonable behavior. The context
parameter to the test methods are primarily used to pass in test dispatchers, and
those dispatchers often really only need to be used for workers.

Since I don't know of a use case for specifying context separately just for workers,
this also removes the `WorkflowTestParams.workerContext` property.
zach-klippenstein added a commit that referenced this pull request Feb 6, 2020
This is an enhancement to #940 that gives more reasonable behavior. The context
parameter to the test methods are primarily used to pass in test dispatchers, and
those dispatchers often really only need to be used for workers.

Since I don't know of a use case for specifying context separately just for workers,
this also removes the `WorkflowTestParams.workerContext` property.
zach-klippenstein added a commit that referenced this pull request Feb 6, 2020
This is an enhancement to #940 that gives more reasonable behavior. The context
parameter to the test methods are primarily used to pass in test dispatchers, and
those dispatchers often really only need to be used for workers.

Since I don't know of a use case for specifying context separately just for workers,
this also removes the `WorkflowTestParams.workerContext` property.
zach-klippenstein added a commit that referenced this pull request Feb 11, 2020
PRs #940 and #943 have a bug where the worker context isn't passed from a parent workflow
to child `WorkflowNode`s. This fixes that.
zach-klippenstein added a commit that referenced this pull request Feb 11, 2020
PRs #940 and #943 have a bug where the worker context isn't passed from a parent workflow
to child `WorkflowNode`s. This fixes that.
@zach-klippenstein zach-klippenstein added the kotlin Affects the Kotlin library. label Feb 28, 2020
zach-klippenstein added a commit to square/workflow-kotlin that referenced this pull request Jun 20, 2020
First part of Kotlin implementation of square/workflow#1021.

Kotlin counterpart to square/workflow#1174.

This implementation intentionally does not run the side effect coroutine
on the `workerContext` `CoroutineContext` that is threaded through the
runtime for testing infrastructure. Initially, workers ran in the same
context as the workflow runtime. The behavior of running workers on a
different dispatcher by default (`Unconfined`) was introduced in
square/workflow#851 as an optimization to reduce
the overhead for running workers that only perform wiring tasks with
other async libraries. This was a theoretical optimization, since running
on the `Unconfined` dispatcher inherently involves less dispatching work,
but the overhead of dispatching wiring coroutines was never actually shown
to be a problem. Additionally, because tests often need to be in full
control of dispatchers, the ability to override the context used for
workers was introduced in square/workflow#940,
which introduced `workerContext`. I am dropping that complexity here
because it adds a decent amount of complexity to worker/side effect
machinery without any proven value. It is also complexity that needs to
be documented, and is probably just more confusing than anything. The
old behavior for workers is maintained for now to reduce the risk of this
change, but side effects will always run in the workflow runtime's
context. This is nice and simple and unsurprising and easy to reason
about.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kotlin Affects the Kotlin library.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants