forked from temporalio/sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_utils.rb
More file actions
76 lines (72 loc) · 1.94 KB
/
workflow_utils.rb
File metadata and controls
76 lines (72 loc) · 1.94 KB
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
# frozen_string_literal: true
require 'securerandom'
require 'temporalio/client'
require 'temporalio/testing'
require 'temporalio/worker'
require 'temporalio/workflow'
require 'test'
module WorkflowUtils
# @type instance: Test
def execute_workflow(
workflow,
*args,
activities: [],
more_workflows: [],
task_queue: "tq-#{SecureRandom.uuid}",
id: "wf-#{SecureRandom.uuid}",
search_attributes: nil,
memo: nil,
retry_policy: nil,
workflow_failure_exception_types: [],
max_cached_workflows: 1000,
logger: nil,
client: env.client,
workflow_payload_codec_thread_pool: nil,
id_conflict_policy: Temporalio::WorkflowIDConflictPolicy::UNSPECIFIED,
max_heartbeat_throttle_interval: 60.0,
task_timeout: nil,
interceptors: [],
on_worker_run: nil,
start_workflow_client: client
)
worker = Temporalio::Worker.new(
client:,
task_queue:,
activities:,
workflows: [workflow] + more_workflows,
workflow_failure_exception_types:,
max_cached_workflows:,
logger: logger || client.options.logger,
workflow_payload_codec_thread_pool:,
max_heartbeat_throttle_interval:,
interceptors:
)
worker.run do
on_worker_run&.call
handle = start_workflow_client.start_workflow(
workflow,
*args,
id:,
task_queue: worker.task_queue,
search_attributes:,
memo:,
retry_policy:,
id_conflict_policy:,
task_timeout:
)
if block_given?
yield handle, worker
else
handle.result
end
end
end
def assert_eventually_task_fail(handle:, message_contains: nil)
assert_eventually do
event = handle.fetch_history_events.find(&:workflow_task_failed_event_attributes)
refute_nil event
assert_includes(event.workflow_task_failed_event_attributes.failure.message, message_contains) if message_contains
event
end
end
end