sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

TestWorkflowEnvironment workflow Context does not block when canceled

Open emetsger opened this issue 11 months ago • 0 comments

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 defered funcs.

Two observations:

  1. The expected behavior seems to only occur in the production runtime when WaitForCancellation activity option is true.
  2. The expected behavior does not occur at all in the test runtime (i.e., using TestWorkflowEnvironment). In testing, the workflow does not block, regardless of WaitForCancellation.

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

emetsger avatar Mar 23 '24 15:03 emetsger