From 61b6d24dd76313fa13d63b7da43b29fa5bf981c3 Mon Sep 17 00:00:00 2001 From: Lina Jodoin Date: Wed, 8 Apr 2026 10:19:28 -0700 Subject: [PATCH] Add a schedule feature test for ErrScheduleAlreadyRunning --- features/features.go | 2 + features/schedule/duplicate_error/feature.go | 50 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 features/schedule/duplicate_error/feature.go diff --git a/features/features.go b/features/features.go index 441964a3..6214c2f4 100644 --- a/features/features.go +++ b/features/features.go @@ -41,6 +41,7 @@ import ( schedule_backfill "github.com/temporalio/features/features/schedule/backfill" schedule_basic "github.com/temporalio/features/features/schedule/basic" schedule_cron "github.com/temporalio/features/features/schedule/cron" + schedule_duplicate_error "github.com/temporalio/features/features/schedule/duplicate_error" schedule_pause "github.com/temporalio/features/features/schedule/pause" schedule_trigger "github.com/temporalio/features/features/schedule/trigger" signal_external "github.com/temporalio/features/features/signal/external" @@ -101,6 +102,7 @@ func init() { schedule_backfill.Feature, schedule_basic.Feature, schedule_cron.Feature, + schedule_duplicate_error.Feature, schedule_pause.Feature, schedule_trigger.Feature, signal_external.Feature, diff --git a/features/schedule/duplicate_error/feature.go b/features/schedule/duplicate_error/feature.go new file mode 100644 index 00000000..a0d69aab --- /dev/null +++ b/features/schedule/duplicate_error/feature.go @@ -0,0 +1,50 @@ +package duplicate_error + +import ( + "context" + "errors" + "time" + + "github.com/google/uuid" + "github.com/temporalio/features/harness/go/harness" + "go.temporal.io/sdk/client" + "go.temporal.io/sdk/temporal" + "go.temporal.io/sdk/workflow" +) + +var Feature = harness.Feature{ + Workflows: Workflow, + Execute: Execute, +} + +func Workflow(ctx workflow.Context) error { return nil } + +func Execute(ctx context.Context, r *harness.Runner) (client.WorkflowRun, error) { + scheduleID := uuid.NewString() + opts := client.ScheduleOptions{ + ID: scheduleID, + Spec: client.ScheduleSpec{Intervals: []client.ScheduleIntervalSpec{{Every: 1 * time.Hour}}}, + Action: &client.ScheduleWorkflowAction{ + ID: uuid.NewString(), + Workflow: Workflow, + TaskQueue: r.TaskQueue, + }, + Paused: true, + } + + handle, err := r.Client.ScheduleClient().Create(ctx, opts) + r.Require.NoError(err) + defer func() { + if err := handle.Delete(context.Background()); err != nil { + r.Log.Warn("Failed deleting schedule handle", "error", err) + } + }() + + // Creating again with the same schedule ID should return ErrScheduleAlreadyRunning. + _, err = r.Client.ScheduleClient().Create(ctx, opts) + r.Require.Error(err) + r.Require.True(errors.Is(err, temporal.ErrScheduleAlreadyRunning), + "expected ErrScheduleAlreadyRunning, got: %v", err) + + return nil, nil +}