Skip to content

Commit 61b6d24

Browse files
committed
Add a schedule feature test for ErrScheduleAlreadyRunning
1 parent 8d7e447 commit 61b6d24

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

features/features.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
schedule_backfill "github.com/temporalio/features/features/schedule/backfill"
4242
schedule_basic "github.com/temporalio/features/features/schedule/basic"
4343
schedule_cron "github.com/temporalio/features/features/schedule/cron"
44+
schedule_duplicate_error "github.com/temporalio/features/features/schedule/duplicate_error"
4445
schedule_pause "github.com/temporalio/features/features/schedule/pause"
4546
schedule_trigger "github.com/temporalio/features/features/schedule/trigger"
4647
signal_external "github.com/temporalio/features/features/signal/external"
@@ -101,6 +102,7 @@ func init() {
101102
schedule_backfill.Feature,
102103
schedule_basic.Feature,
103104
schedule_cron.Feature,
105+
schedule_duplicate_error.Feature,
104106
schedule_pause.Feature,
105107
schedule_trigger.Feature,
106108
signal_external.Feature,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)