Skip to content

Commit

Permalink
Add support for unit testing child workflows that call continue-as-new (
Browse files Browse the repository at this point in the history
temporalio#1437)

* Added Test_ChildWorkflow_ContinueAsNew

* Added unit testing support for child workflows that call continue-as-new

* Removed unnecessary workflow registration, fixed Test_WorkflowHeaderContext
  • Loading branch information
mfateev authored Apr 9, 2024
1 parent 108aac8 commit a02b92e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 79 deletions.
18 changes: 16 additions & 2 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,22 @@ func (h *testWorkflowHandle) rerunAsChild() bool {
return false
}
params := h.params

var continueAsNewErr *ContinueAsNewError
if errors.As(env.testError, &continueAsNewErr) {
params.Input = continueAsNewErr.Input
params.Header = continueAsNewErr.Header
params.RetryPolicy = convertToPBRetryPolicy(continueAsNewErr.RetryPolicy)
params.WorkflowType = continueAsNewErr.WorkflowType
params.TaskQueueName = continueAsNewErr.TaskQueueName
params.VersioningIntent = continueAsNewErr.VersioningIntent
params.WorkflowRunTimeout = continueAsNewErr.WorkflowRunTimeout
params.WorkflowTaskTimeout = continueAsNewErr.WorkflowTaskTimeout
// remove the current child workflow from the pending child workflow map because
// the childWorkflowID will be the same for retry run.
delete(env.runningWorkflows, env.workflowInfo.WorkflowExecution.ID)
env.parentEnv.ExecuteChildWorkflow(*params, h.callback, nil /* child workflow already started */)
return true
}
// pass down the last completion result
var result *commonpb.Payloads
// TODO (shtin): convert env.testResult to *commonpb.Payloads
Expand All @@ -1036,7 +1051,6 @@ func (h *testWorkflowHandle) rerunAsChild() bool {
result = env.workflowInfo.lastCompletionResult
}
params.lastCompletionResult = result

if params.RetryPolicy != nil && env.testError != nil {
var expireTime time.Time
if params.WorkflowOptions.WorkflowExecutionTimeout > 0 {
Expand Down
Loading

0 comments on commit a02b92e

Please sign in to comment.