@@ -204,6 +204,34 @@ func workflowTimerCancellation(ctx workflow.Context) (time.Time, error) {
204
204
return workflow .Now (ctx ), nil
205
205
}
206
206
207
+ func Test_TimerRespondingWithoutNewEvents (t * testing.T ) {
208
+ tester := NewWorkflowTester [time.Time ](workflowTimerRespondingWithoutNewEvents )
209
+
210
+ tester .ScheduleCallback (time .Duration (2 * time .Second ), func () {
211
+ tester .SignalWorkflow ("signal" , "s42" )
212
+ })
213
+
214
+ tester .Execute ()
215
+
216
+ require .True (t , tester .WorkflowFinished ())
217
+
218
+ _ , err := tester .WorkflowResult ()
219
+ require .Empty (t , err )
220
+ }
221
+
222
+ func workflowTimerRespondingWithoutNewEvents (ctx workflow.Context ) error {
223
+ workflow .ScheduleTimer (ctx , 1 * time .Second ).Get (ctx )
224
+
225
+ workflow .Select (
226
+ ctx ,
227
+ workflow .Receive (workflow .NewSignalChannel [any ](ctx , "signal" ), func (ctx workflow.Context , signal any , ok bool ) {
228
+ // do nothing
229
+ }),
230
+ )
231
+
232
+ return nil
233
+ }
234
+
207
235
func Test_Signals (t * testing.T ) {
208
236
tester := NewWorkflowTester [string ](workflowSignal )
209
237
tester .ScheduleCallback (time .Duration (5 * time .Second ), func () {
@@ -263,3 +291,40 @@ func workflowSubWorkFlowsAndSignals(ctx workflow.Context) (string, error) {
263
291
func workflowSum (ctx workflow.Context , valA , valB int ) (int , error ) {
264
292
return valA + valB , nil
265
293
}
294
+
295
+ func Test_SignalSubWorkflow (t * testing.T ) {
296
+ tester := NewWorkflowTester [int ](workflowSubworkflowSignal )
297
+ require .NoError (t , tester .Registry ().RegisterWorkflow (waitForSignal ))
298
+
299
+ tester .Execute ()
300
+
301
+ require .True (t , tester .WorkflowFinished ())
302
+ wfR , wfErr := tester .WorkflowResult ()
303
+ require .Empty (t , wfErr )
304
+ require .Equal (t , 42 , wfR )
305
+ }
306
+
307
+ func workflowSubworkflowSignal (ctx workflow.Context ) (int , error ) {
308
+ sw := workflow .CreateSubWorkflowInstance [int ](ctx , workflow.SubWorkflowOptions {
309
+ InstanceID : "subworkflow" ,
310
+ }, waitForSignal )
311
+
312
+ _ , err := workflow .SignalWorkflow (ctx , "subworkflow" , "signal" , "" ).Get (ctx )
313
+ if err != nil {
314
+ return 0 , err
315
+ }
316
+
317
+ // Wait for subworkflow and return result
318
+ return sw .Get (ctx )
319
+ }
320
+
321
+ func waitForSignal (ctx workflow.Context ) (int , error ) {
322
+ workflow .Select (
323
+ ctx ,
324
+ workflow .Receive (workflow .NewSignalChannel [any ](ctx , "signal" ), func (ctx workflow.Context , signal any , ok bool ) {
325
+ // Do nothing
326
+ }),
327
+ )
328
+
329
+ return 42 , nil
330
+ }
0 commit comments