-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathupdate_schedule_spec.rb
103 lines (90 loc) · 3.93 KB
/
update_schedule_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "temporal/errors"
require "temporal/schedule/schedule"
require "temporal/schedule/schedule_spec"
require "temporal/schedule/schedule_policies"
require "temporal/schedule/schedule_state"
require "temporal/schedule/start_workflow_action"
describe "Temporal.update_schedule", :integration do
let(:example_schedule) do
Temporal::Schedule::Schedule.new(
spec: Temporal::Schedule::ScheduleSpec.new(
cron_expressions: ["@hourly"],
jitter: 30,
# Set an end time so that the test schedule doesn't run forever
end_time: Time.now + 600
),
action: Temporal::Schedule::StartWorkflowAction.new(
"HelloWorldWorkflow",
"Test",
options: {
task_queue: integration_spec_task_queue
}
),
policies: Temporal::Schedule::SchedulePolicies.new(
overlap_policy: :buffer_one
),
state: Temporal::Schedule::ScheduleState.new(
notes: "Created by integration test"
)
)
end
let(:updated_schedule) do
Temporal::Schedule::Schedule.new(
spec: Temporal::Schedule::ScheduleSpec.new(
cron_expressions: ["@hourly"],
jitter: 500,
# Set an end time so that the test schedule doesn't run forever
end_time: Time.now + 600
),
action: Temporal::Schedule::StartWorkflowAction.new(
"HelloWorldWorkflow",
"UpdatedInput",
options: {
task_queue: integration_spec_task_queue
}
),
policies: Temporal::Schedule::SchedulePolicies.new(
overlap_policy: :buffer_all
),
state: Temporal::Schedule::ScheduleState.new(
notes: "Updated by integration test"
)
)
end
it "can update schedules" do
namespace = integration_spec_namespace
schedule_id = SecureRandom.uuid
Temporal.create_schedule(namespace, schedule_id, example_schedule)
describe_response = Temporal.describe_schedule(namespace, schedule_id)
expect(describe_response.schedule.spec.jitter.seconds).to(eq(30))
expect(describe_response.schedule.policies.overlap_policy).to(eq(:SCHEDULE_OVERLAP_POLICY_BUFFER_ONE))
expect(describe_response.schedule.action.start_workflow.workflow_type.name).to(eq("HelloWorldWorkflow"))
expect(describe_response.schedule.state.notes).to(eq("Created by integration test"))
Temporal.update_schedule(namespace, schedule_id, updated_schedule)
updated_describe = Temporal.describe_schedule(namespace, schedule_id)
expect(updated_describe.schedule.spec.jitter.seconds).to(eq(500))
expect(updated_describe.schedule.policies.overlap_policy).to(eq(:SCHEDULE_OVERLAP_POLICY_BUFFER_ALL))
expect(updated_describe.schedule.state.notes).to(eq("Updated by integration test"))
end
it "does not update if conflict token doesnt match" do
namespace = integration_spec_namespace
schedule_id = SecureRandom.uuid
initial_response = Temporal.create_schedule(namespace, schedule_id, example_schedule)
# Update the schedule but pass the incorrect token
Temporal.update_schedule(namespace, schedule_id, updated_schedule, conflict_token: "invalid token")
# The schedule should not have been updated (we don't get an error message from the server in this case)
describe_response = Temporal.describe_schedule(namespace, schedule_id)
expect(describe_response.schedule.spec.jitter.seconds).to(eq(30))
# If we pass the right conflict token the update should be applied
Temporal.update_schedule(namespace, schedule_id, updated_schedule, conflict_token: initial_response.conflict_token)
updated_describe = Temporal.describe_schedule(namespace, schedule_id)
expect(updated_describe.schedule.spec.jitter.seconds).to(eq(500))
end
it "raises a NotFoundFailure if a schedule doesn't exist" do
namespace = integration_spec_namespace
expect do
Temporal.update_schedule(namespace, "some-invalid-schedule-id", updated_schedule)
end
.to(raise_error(Temporal::NotFoundFailure))
end
end