Expose SetContinuedAsNewRunID in the TestWorkflowEnvironment #1246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was changed
This extends the
TestWorkflowEnvironment
to expose a newSetContinuedAsNewRunID
API to set the workflow under testContinuedAsNewRunID
field in itsWorkflowInfo
.Why?
When building some workflows ("actors" like ones are a good example), you sometimes want to be able to distinguish when a workflow is starting and when it's being continued as new. This allows you to execute different behavior like restoring some state from an external system.
One way to check if your current workflow execution has been continued as new is to inspect the workflow info
ContinuedAsNewRunID
field. When it's set, then you now you are not starting fresh. It is nice because you don't need any special field in your workflow inputs to detect such cases.Example:
When testing such workflows though, you may want to test behavior only after a first
ContinueAsNew
call has been made. The easiest way to do that is to setup the test environment to fill up the workflow infoContinuedAsNewRunID
field.This is what this commit is doing, it extends the
TestWorkflowEnvironment
to expose aSetContinuedExecutionID
field to an arbitrary value.This way in workflow unit tests, we can skip the code paths we don't care about and don't resort to mocking activities and child workflows for nothing leading to easier to implement and easier to read tests.
Checklist
N/A
I only added a unit test (so far).
We probably want to rely on Godocs for that API.
Thoughts?