@@ -121,6 +121,7 @@ type workflowTester[TResult any] struct {
121
121
122
122
workflowHistory []history.Event
123
123
clock * clock.Mock
124
+ startTime time.Time
124
125
125
126
timers []* testTimer
126
127
callbacks chan func () * history.WorkflowEvent
@@ -149,7 +150,7 @@ func WithTestTimeout(timeout time.Duration) WorkflowTesterOption {
149
150
}
150
151
151
152
func NewWorkflowTester [TResult any ](wf interface {}, opts ... WorkflowTesterOption ) WorkflowTester [TResult ] {
152
- // Start with the current wall-clock tiem
153
+ // Start with the current wall-clock time
153
154
clock := clock .NewMock ()
154
155
clock .Set (time .Now ())
155
156
@@ -246,6 +247,9 @@ func (wt *workflowTester[TResult]) OnSubWorkflow(workflow interface{}, args ...i
246
247
}
247
248
248
249
func (wt * workflowTester [TResult ]) Execute (args ... interface {}) {
250
+ // Record start time of test run
251
+ wt .startTime = wt .clock .Now ()
252
+
249
253
// Start workflow under test
250
254
initialEvent := wt .getInitialEvent (wt .wf , args )
251
255
wt .addWorkflow (wt .wfi , initialEvent )
@@ -344,13 +348,10 @@ func (wt *workflowTester[TResult]) Execute(args ...interface{}) {
344
348
default :
345
349
}
346
350
347
- // If there are no running activities and timers, skip time
348
- if wt .runningActivities == 0 && len (wt .timers ) > 0 {
349
- // Take first timer and execute it
350
- sort .SliceStable (wt .timers , func (i , j int ) bool {
351
- return wt .timers [i ].At .Before (wt .timers [j ].At )
352
- })
351
+ // If there are no running activities and timers, skip time and jump to the next scheduled timer
353
352
353
+ if atomic .LoadInt32 (& wt .runningActivities ) == 0 && len (wt .timers ) > 0 {
354
+ // Take first timer and execute it
354
355
t := wt .timers [0 ]
355
356
wt .timers = wt .timers [1 :]
356
357
@@ -554,6 +555,10 @@ func (wt *workflowTester[TResult]) scheduleTimer(instance *core.WorkflowInstance
554
555
}
555
556
},
556
557
})
558
+
559
+ sort .SliceStable (wt .timers , func (i , j int ) bool {
560
+ return wt .timers [i ].At .Before (wt .timers [j ].At )
561
+ })
557
562
}
558
563
559
564
func (wt * workflowTester [TResult ]) cancelTimer (instance * core.WorkflowInstance , event history.Event ) {
0 commit comments