sdk-go
sdk-go copied to clipboard
TestWorkflowEnvironment workflow Context does not block when canceled
Expected Behavior
I expect the test environment to have parity with the production runtime environment.
When a workflow receives a cancellation request whilst a non-heartbeating activity is executing, I expect the workflow to block waiting for the activity to return before advancing the workflow, including the execution of any defer
ed funcs.
Two observations:
- The expected behavior seems to only occur in the production runtime when
WaitForCancellation
activity option istrue
. - The expected behavior does not occur at all in the test runtime (i.e., using
TestWorkflowEnvironment
). In testing, the workflow does not block, regardless ofWaitForCancellation
.
This issue and test case relates to observation #2. I was trying to write a test case for #1, and encountered buggy behavior in the test environment.
See additional context in Slack.
Actual Behavior
In the test runtime, the workflow receives a cancelation request and immediately moves on to executing deferred without waiting for the currently executing activity to complete.
Steps to Reproduce the Problem
Run the supplied test case
The test case expects the activity in the main body of the workflow to complete before the activity in the deferred func. The test case demonstrates that the deferred activity executes while the main activity is still running.
The test issues a cancelation request using a delayed callback, and the activity uses time.Sleep()
to ensure that cancelation occurs while the activity is executing.
Specifications
- Version:
go.temporal.io/sdk v1.26.0
,go.temporal.io/sdk v1.25.1
- Platform:
Darwin Kernel Version 22.6.0
,go version go1.21.4 darwin/arm64