Skip to content

Commit 77b8ecf

Browse files
committed
Ensure only a single wall clock timer is scheduled
1 parent 605a7b6 commit 77b8ecf

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tester/tester.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ func (wt *workflowTester[TResult]) fireTimer() bool {
423423

424424
case TM_WallClock:
425425
{
426+
if wt.wallClockTimer != nil {
427+
// Wall-clock timer already scheduled
428+
return false
429+
}
430+
426431
t := wt.timers[0]
427432

428433
wt.logger.Debug("Scheduling wall-clock timer", "at", t.At)

tester/tester_timers_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,35 @@ func Test_Timers_SetsTimeModeCorrectly(t *testing.T) {
210210
require.Empty(t, werr)
211211
tester.AssertExpectations(t)
212212
}
213+
214+
func Test_Timers_MultipleTimers(t *testing.T) {
215+
activity1 := func() error {
216+
return nil
217+
}
218+
219+
wf := func(ctx workflow.Context) error {
220+
for i := 0; i < 10; i++ {
221+
222+
tctx, cancel := workflow.WithCancel(ctx)
223+
workflow.ScheduleTimer(tctx, time.Millisecond*10)
224+
workflow.ExecuteActivity[string](ctx, workflow.DefaultActivityOptions, activity1).Get(ctx)
225+
226+
cancel()
227+
}
228+
229+
return nil
230+
}
231+
232+
dl := newDebugLogger()
233+
234+
tester := NewWorkflowTester[string](wf, WithTestTimeout(time.Second*3), WithLogger(dl))
235+
236+
tester.OnActivity(activity1).Return("activity", nil)
237+
238+
tester.Execute()
239+
240+
require.True(t, tester.WorkflowFinished())
241+
_, werr := tester.WorkflowResult()
242+
require.Empty(t, werr)
243+
tester.AssertExpectations(t)
244+
}

0 commit comments

Comments
 (0)