Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions features/schedule/duplicate_error/feature.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading