Skip to content

Commit 4c19fa4

Browse files
committed
Do not run timers when activites are running
1 parent 4093d8f commit 4c19fa4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tester/tester.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ func (wt *workflowTester[TResult]) Execute(args ...interface{}) {
295295
}
296296
}
297297

298+
// Schedule activities
299+
for _, event := range result.ActivityEvents {
300+
gotNewEvents = true
301+
302+
a := event.Attributes.(*history.ActivityScheduledAttributes)
303+
wt.logger.Debug("Activity event", "activity", a.Name)
304+
305+
wt.scheduleActivity(tw.instance, event)
306+
}
307+
298308
for _, workflowEvent := range result.WorkflowEvents {
299309
gotNewEvents = true
300310
wt.logger.Debug("Workflow event", "event_type", workflowEvent.HistoryEvent.Type)
@@ -334,7 +344,8 @@ func (wt *workflowTester[TResult]) Execute(args ...interface{}) {
334344
default:
335345
}
336346

337-
if len(wt.timers) > 0 {
347+
// If there are no running activities and timers, skip time
348+
if wt.runningActivities == 0 && len(wt.timers) > 0 {
338349
// Take first timer and execute it
339350
sort.SliceStable(wt.timers, func(i, j int) bool {
340351
return wt.timers[i].At.Before(wt.timers[j].At)
@@ -431,8 +442,9 @@ func (wt *workflowTester[TResult]) AssertExpectations(t *testing.T) {
431442
func (wt *workflowTester[TResult]) scheduleActivity(wfi *core.WorkflowInstance, event history.Event) {
432443
e := event.Attributes.(*history.ActivityScheduledAttributes)
433444

445+
atomic.AddInt32(&wt.runningActivities, 1)
446+
434447
go func() {
435-
atomic.AddInt32(&wt.runningActivities, 1)
436448
defer atomic.AddInt32(&wt.runningActivities, -1)
437449

438450
var activityErr error

0 commit comments

Comments
 (0)