Skip to content

Commit a9d44df

Browse files
committed
improve tests
1 parent c2ca06f commit a9d44df

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

temporalio/test/client_schedule_test.rb

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def test_basics # rubocop:disable Metrics/AbcSize
5353
policy: Temporalio::Client::Schedule::Policy.new(
5454
overlap: Temporalio::Client::Schedule::OverlapPolicy::BUFFER_ONE,
5555
catchup_window: 5 * 60.0,
56-
pause_on_failure: true,
57-
keep_original_workflow_id: true
56+
pause_on_failure: true
5857
),
5958
state: Temporalio::Client::Schedule::State.new(
6059
note: 'sched note 1',
@@ -125,7 +124,6 @@ def test_basics # rubocop:disable Metrics/AbcSize
125124
new_schedule = Temporalio::Client::Schedule.new(
126125
action:,
127126
spec: Temporalio::Client::Schedule::Spec.new,
128-
policy: Temporalio::Client::Schedule::Policy.new(keep_original_workflow_id: true),
129127
state: Temporalio::Client::Schedule::State.new(paused: true)
130128
)
131129
handle.update { Temporalio::Client::Schedule::Update.new(schedule: new_schedule) }
@@ -172,7 +170,6 @@ def test_basics # rubocop:disable Metrics/AbcSize
172170
# Check results
173171
exec = desc.info.recent_actions.first&.action #: Temporalio::Client::Schedule::ActionExecution::StartWorkflow
174172
assert_instance_of Temporalio::Client::Schedule::ActionExecution::StartWorkflow, exec
175-
assert_equal action.id, exec.workflow_id
176173
assert_equal 'some-result',
177174
env.client.workflow_handle(exec.workflow_id,
178175
first_execution_run_id: exec.first_execution_run_id).result
@@ -261,7 +258,7 @@ def test_calendar_spec_defaults
261258
assert_equal desc.info.next_action_times[i - 1] + (24 * 60 * 60), next_action_time unless i.zero?
262259
end
263260
ensure
264-
delete_schedules(handle.id) if defined?(handle)
261+
delete_schedules(handle.id) if defined?(handle) && handle
265262
end
266263

267264
def test_trigger_immediately
@@ -345,4 +342,79 @@ def test_backfill
345342
ensure
346343
delete_schedules(handle.id) if defined?(handle)
347344
end
345+
346+
def test_keep_original_workflow_id_policy_on_create
347+
assert_no_schedules
348+
349+
task_queue = "tq-#{SecureRandom.uuid}"
350+
handle = env.client.create_schedule(
351+
"sched-#{SecureRandom.uuid}",
352+
Temporalio::Client::Schedule.new(
353+
action: Temporalio::Client::Schedule::Action::StartWorkflow.new(
354+
'kitchen_sink',
355+
{ actions: [{ result: { value: 'some-result' } }] },
356+
id: "wf-#{SecureRandom.uuid}",
357+
task_queue:
358+
),
359+
spec: Temporalio::Client::Schedule::Spec.new(
360+
intervals: [Temporalio::Client::Schedule::Spec::Interval.new(every: 60.0)]
361+
),
362+
policy: Temporalio::Client::Schedule::Policy.new(keep_original_workflow_id: true),
363+
state: Temporalio::Client::Schedule::State.new(paused: true)
364+
)
365+
)
366+
367+
desc = handle.describe
368+
assert desc.schedule.policy.keep_original_workflow_id
369+
assert desc.raw_description.schedule.policies.keep_original_workflow_id
370+
ensure
371+
delete_schedules(handle.id) if defined?(handle)
372+
end
373+
374+
def test_keep_original_workflow_id_policy_on_update
375+
assert_no_schedules
376+
377+
task_queue = "tq-#{SecureRandom.uuid}"
378+
handle = env.client.create_schedule(
379+
"sched-#{SecureRandom.uuid}",
380+
Temporalio::Client::Schedule.new(
381+
action: Temporalio::Client::Schedule::Action::StartWorkflow.new(
382+
'kitchen_sink',
383+
{ actions: [{ result: { value: 'some-result' } }] },
384+
id: "wf-#{SecureRandom.uuid}",
385+
task_queue:
386+
),
387+
spec: Temporalio::Client::Schedule::Spec.new(
388+
intervals: [Temporalio::Client::Schedule::Spec::Interval.new(every: 60.0)]
389+
),
390+
state: Temporalio::Client::Schedule::State.new(paused: true)
391+
)
392+
)
393+
394+
desc = handle.describe
395+
refute desc.schedule.policy.keep_original_workflow_id
396+
refute desc.raw_description.schedule.policies.keep_original_workflow_id
397+
398+
handle.update do |input|
399+
updated_schedule = input.description.schedule.with(
400+
policy: input.description.schedule.policy.with(keep_original_workflow_id: true)
401+
)
402+
Temporalio::Client::Schedule::Update.new(schedule: updated_schedule)
403+
end
404+
desc = handle.describe
405+
assert desc.schedule.policy.keep_original_workflow_id
406+
assert desc.raw_description.schedule.policies.keep_original_workflow_id
407+
408+
handle.update do |input|
409+
updated_schedule = input.description.schedule.with(
410+
policy: input.description.schedule.policy.with(keep_original_workflow_id: false)
411+
)
412+
Temporalio::Client::Schedule::Update.new(schedule: updated_schedule)
413+
end
414+
desc = handle.describe
415+
refute desc.schedule.policy.keep_original_workflow_id
416+
refute desc.raw_description.schedule.policies.keep_original_workflow_id
417+
ensure
418+
delete_schedules(handle.id) if defined?(handle) && handle
419+
end
348420
end

0 commit comments

Comments
 (0)