Skip to content

Commit

Permalink
Merge branch 'master' into debug-TestSideEffectDefer
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Feb 23, 2024
2 parents 572b524 + a71e4c4 commit 6ac2bd0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ["1.20", "1.21"]
go-version: ["1.21", "1.22"]
include:
- os: ubuntu-latest
go-version: "1.21"
go-version: "1.22"
# We only want to upload coverage on a single target
uploadCoverage: true
# We only want to check docker compose on a single target
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
cloud-test:
strategy:
matrix:
go-version: ["1.20", "1.21"]
go-version: ["1.21", "1.22"]
# Try to avoid running tests in parallel to avoid workflow ID conflict
max-parallel: 1
# Only supported in non-fork runs, since secrets are not available in forks.
Expand Down
8 changes: 6 additions & 2 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2427,12 +2427,16 @@ func (env *testWorkflowEnvironmentImpl) getActivityInfo(activityID ActivityID, a
}

func (env *testWorkflowEnvironmentImpl) cancelWorkflow(callback ResultHandler) {
env.cancelWorkflowByID(env.workflowInfo.WorkflowExecution.ID, env.workflowInfo.WorkflowExecution.RunID, callback)
}

func (env *testWorkflowEnvironmentImpl) cancelWorkflowByID(workflowID string, runID string, callback ResultHandler) {
env.postCallback(func() {
// RequestCancelWorkflow needs to be run in main thread
env.RequestCancelExternalWorkflow(
env.workflowInfo.Namespace,
env.workflowInfo.WorkflowExecution.ID,
env.workflowInfo.WorkflowExecution.RunID,
workflowID,
runID,
callback,
)
}, true)
Expand Down
40 changes: 40 additions & 0 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,46 @@ func (s *WorkflowTestSuiteUnitTest) Test_WorkflowCancellation() {
s.True(errors.As(err, &err1))
}

func (s *WorkflowTestSuiteUnitTest) Test_ChildWorkflowCancellation() {
childWorkflowFn := func(ctx Context) error {
ctx = WithActivityOptions(ctx, s.activityOptions)
f := ExecuteActivity(ctx, testActivityHeartbeat, "msg1", time.Second*10)
err := f.Get(ctx, nil) // wait for result
return err
}

childID := "child_workflow_id"
workflowFn := func(ctx Context) (string, error) {
ctx = WithChildWorkflowOptions(ctx, ChildWorkflowOptions{
WorkflowID: childID,
})
err := ExecuteChildWorkflow(ctx, childWorkflowFn).Get(ctx, nil)
if err != nil {
return err.Error(), nil
}
return "", nil
}

env := s.NewTestWorkflowEnvironment()
env.RegisterDelayedCallback(func() {
env.CancelWorkflowByID(childID, "")
}, time.Second)

env.RegisterWorkflow(workflowFn)
env.RegisterWorkflow(childWorkflowFn)
env.RegisterActivity(testActivityHeartbeat)

env.ExecuteWorkflow(workflowFn)

s.True(env.IsWorkflowCompleted())
err := env.GetWorkflowError()
s.NoError(err)

var res string
s.NoError(env.GetWorkflowResult(&res))
s.Contains(res, "canceled")
}

func testWorkflowHello(ctx Context) (string, error) {
ao := ActivityOptions{
ScheduleToStartTimeout: time.Minute,
Expand Down
5 changes: 5 additions & 0 deletions internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ func (e *TestWorkflowEnvironment) CancelWorkflow() {
e.impl.cancelWorkflow(func(result *commonpb.Payloads, err error) {})
}

// CancelWorkflowByID requests cancellation (through workflow Context) to the specified workflow.
func (e *TestWorkflowEnvironment) CancelWorkflowByID(workflowID string, runID string) {
e.impl.cancelWorkflowByID(workflowID, runID, func(result *commonpb.Payloads, err error) {})
}

// SignalWorkflow sends signal to the currently running test workflow.
func (e *TestWorkflowEnvironment) SignalWorkflow(name string, input interface{}) {
e.impl.signalWorkflow(name, input, true)
Expand Down

0 comments on commit 6ac2bd0

Please sign in to comment.