Skip to content

Commit a73d5f6

Browse files
committed
Test for named timer
1 parent a2f5b03 commit a73d5f6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

workflow/executor/executor_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ func Test_Executor(t *testing.T) {
598598
// Schedule but not wait for timer
599599
wf.ScheduleTimer(ctx, time.Second*2)
600600

601+
// Schedule but not wait for named timer
602+
wf.ScheduleTimer(ctx, time.Second*2, wf.WithTimerName("delay"))
603+
601604
return nil
602605
}
603606

@@ -606,7 +609,7 @@ func Test_Executor(t *testing.T) {
606609

607610
task := startWorkflowTask("instanceID", workflow)
608611

609-
require.PanicsWithValue(t, "workflow completed, but there are still pending futures: [1-subworkflow:1 2-timer:2s]", func() {
612+
require.PanicsWithValue(t, "workflow completed, but there are still pending futures: [1-subworkflow:1 2-timer:2s 3-timer-delay:2s]", func() {
610613
e.ExecuteTask(context.Background(), task)
611614
})
612615
},

workflow/timer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ func ScheduleTimer(ctx Context, delay time.Duration, opts ...timerOption) Future
6161

6262
timerCmd := command.NewScheduleTimerCommand(scheduleEventID, at, timerConfig.Name, traceContext)
6363
wfState.AddCommand(timerCmd)
64-
wfState.TrackFuture(scheduleEventID, workflowstate.AsDecodingSettable(contextvalue.Converter(ctx), fmt.Sprintf("timer:%s:%v", timerConfig.Name, delay), f))
64+
65+
timerSuffix := ""
66+
if timerConfig.Name != "" {
67+
timerSuffix = "-" + timerConfig.Name
68+
}
69+
70+
wfState.TrackFuture(
71+
scheduleEventID,
72+
workflowstate.AsDecodingSettable(contextvalue.Converter(ctx), fmt.Sprintf("timer%s:%v", timerSuffix, delay), f))
6573

6674
cancelReceiver := &sync.Receiver[struct{}]{
6775
Receive: func(v struct{}, ok bool) {

0 commit comments

Comments
 (0)