@@ -3,6 +3,7 @@ package tester
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"testing"
7
8
"time"
8
9
@@ -109,6 +110,47 @@ func Test_SubWorkflow_Mocked_Failure(t *testing.T) {
109
110
tester .AssertExpectations (t )
110
111
}
111
112
113
+ func Test_SubWorkflow_Cancel (t * testing.T ) {
114
+ subWorkflow := func (ctx workflow.Context ) error {
115
+ _ , _ = ctx .Done ().Receive (ctx )
116
+ return ctx .Err ()
117
+ }
118
+
119
+ workflowWithSub := func (ctx workflow.Context ) error {
120
+ _ , err := workflow .CreateSubWorkflowInstance [any ](
121
+ ctx ,
122
+ workflow .DefaultSubWorkflowOptions ,
123
+ subWorkflow ,
124
+ ).Get (ctx )
125
+ if err != nil {
126
+ return fmt .Errorf ("subworkflow: %w" , err )
127
+ }
128
+
129
+ return nil
130
+ }
131
+
132
+ tester := NewWorkflowTester [string ](workflowWithSub )
133
+ tester .Registry ().RegisterWorkflow (subWorkflow )
134
+
135
+ var subWorkflowInstance * core.WorkflowInstance
136
+
137
+ tester .ListenSubWorkflow (func (instance * core.WorkflowInstance , _ string ) {
138
+ subWorkflowInstance = instance
139
+ })
140
+
141
+ tester .ScheduleCallback (time .Millisecond , func () {
142
+ require .NoError (t , tester .CancelWorkflowInstance (subWorkflowInstance ))
143
+ })
144
+
145
+ tester .Execute (context .Background ())
146
+
147
+ require .True (t , tester .WorkflowFinished ())
148
+
149
+ _ , err := tester .WorkflowResult ()
150
+ require .EqualError (t , err , "subworkflow: context canceled" )
151
+ tester .AssertExpectations (t )
152
+ }
153
+
112
154
func Test_SubWorkflow_Signals (t * testing.T ) {
113
155
subWorkflow := func (ctx workflow.Context , input string ) (string , error ) {
114
156
c := workflow .NewSignalChannel [string ](ctx , "subworkflow-signal" )
0 commit comments