Skip to content

Commit

Permalink
Don't run workflowCancelHandler in test harness (temporalio#1296)
Browse files Browse the repository at this point in the history
Don't run workflowCancelHandler in test harness on
completed workflows.
  • Loading branch information
Quinn-With-Two-Ns authored Dec 4, 2023
1 parent 802d32e commit 838121a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 1 addition & 4 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,13 @@ func (env *testWorkflowEnvironmentImpl) Complete(result *commonpb.Payloads, err
return
}
env.workflowDef.Close()
var canceledErr *CanceledError
if errors.As(err, &canceledErr) && env.workflowCancelHandler != nil {
env.workflowCancelHandler()
}

dc := env.GetDataConverter()
env.isWorkflowCompleted = true

if err != nil {
var continueAsNewErr *ContinueAsNewError
var canceledErr *CanceledError
var timeoutErr *TimeoutError
var workflowPanicErr *workflowPanicError
var workflowExecutionAlreadyStartedErr *serviceerror.WorkflowExecutionAlreadyStarted
Expand Down
14 changes: 14 additions & 0 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityMockFunctionZero() {
env.AssertExpectations(s.T())
}

func (s *WorkflowTestSuiteUnitTest) Test_WorkflowReturnedCancel() {
env := s.NewTestWorkflowEnvironment()
env.RegisterWorkflow(testWorkflowCancelled)
env.ExecuteWorkflow(testWorkflowCancelled)

s.True(env.IsWorkflowCompleted())
s.Error(env.GetWorkflowError())
}

func (s *WorkflowTestSuiteUnitTest) Test_ActivityByNameMockFunction() {
mockActivity := func(ctx context.Context, msg string) (string, error) {
return "mock_" + msg, nil
Expand Down Expand Up @@ -610,6 +619,11 @@ func testWorkflowHello(ctx Context) (string, error) {
return result, nil
}

func testWorkflowCancelled(ctx Context) error {
_ = NewTimer(ctx, 20*time.Minute)
return NewCanceledError()
}

func testWorkflowContext(ctx Context) (string, error) {
value := ctx.Value(contextKey(testHeader))
if val, ok := value.(string); ok {
Expand Down

0 comments on commit 838121a

Please sign in to comment.