|
| 1 | +package duplicate_error |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/google/uuid" |
| 9 | + "github.com/temporalio/features/harness/go/harness" |
| 10 | + "go.temporal.io/sdk/client" |
| 11 | + "go.temporal.io/sdk/temporal" |
| 12 | + "go.temporal.io/sdk/workflow" |
| 13 | +) |
| 14 | + |
| 15 | +var Feature = harness.Feature{ |
| 16 | + Workflows: Workflow, |
| 17 | + Execute: Execute, |
| 18 | +} |
| 19 | + |
| 20 | +func Workflow(ctx workflow.Context) error { return nil } |
| 21 | + |
| 22 | +func Execute(ctx context.Context, r *harness.Runner) (client.WorkflowRun, error) { |
| 23 | + scheduleID := uuid.NewString() |
| 24 | + opts := client.ScheduleOptions{ |
| 25 | + ID: scheduleID, |
| 26 | + Spec: client.ScheduleSpec{Intervals: []client.ScheduleIntervalSpec{{Every: 1 * time.Hour}}}, |
| 27 | + Action: &client.ScheduleWorkflowAction{ |
| 28 | + ID: uuid.NewString(), |
| 29 | + Workflow: Workflow, |
| 30 | + TaskQueue: r.TaskQueue, |
| 31 | + }, |
| 32 | + Paused: true, |
| 33 | + } |
| 34 | + |
| 35 | + handle, err := r.Client.ScheduleClient().Create(ctx, opts) |
| 36 | + r.Require.NoError(err) |
| 37 | + defer func() { |
| 38 | + if err := handle.Delete(context.Background()); err != nil { |
| 39 | + r.Log.Warn("Failed deleting schedule handle", "error", err) |
| 40 | + } |
| 41 | + }() |
| 42 | + |
| 43 | + // Creating again with the same schedule ID should return ErrScheduleAlreadyRunning. |
| 44 | + _, err = r.Client.ScheduleClient().Create(ctx, opts) |
| 45 | + r.Require.Error(err) |
| 46 | + r.Require.True(errors.Is(err, temporal.ErrScheduleAlreadyRunning), |
| 47 | + "expected ErrScheduleAlreadyRunning, got: %v", err) |
| 48 | + |
| 49 | + return nil, nil |
| 50 | +} |
0 commit comments