forked from coinbase/temporal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_workflow_spec.rb
96 lines (79 loc) · 2.77 KB
/
start_workflow_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
require 'workflows/hello_world_workflow'
require 'workflows/long_workflow'
describe 'Temporal.start_workflow' do
let(:workflow_id) { SecureRandom.uuid }
it 'starts a workflow using a class reference' do
run_id = Temporal.start_workflow(HelloWorldWorkflow, 'Test', options: {
workflow_id: workflow_id
})
result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: run_id
)
expect(result).to eq('Hello World, Test')
end
it 'starts a workflow using a string reference' do
run_id = Temporal.start_workflow('HelloWorldWorkflow', 'Test', options: {
workflow_id: workflow_id,
namespace: Temporal.configuration.namespace,
task_queue: Temporal.configuration.task_queue
})
result = Temporal.await_workflow_result(
'HelloWorldWorkflow',
workflow_id: workflow_id,
run_id: run_id,
namespace: Temporal.configuration.namespace
)
expect(result).to eq('Hello World, Test')
end
it 'rejects duplicate workflow ids based on workflow_id_reuse_policy' do
# Run it once...
run_id = Temporal.start_workflow(HelloWorldWorkflow, 'Test', options: {
workflow_id: workflow_id,
})
result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: run_id
)
expect(result).to eq('Hello World, Test')
# And again, allowing duplicates...
run_id = Temporal.start_workflow(HelloWorldWorkflow, 'Test', options: {
workflow_id: workflow_id,
workflow_id_reuse_policy: :allow
})
Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: run_id
)
# And again, rejecting duplicates...
expect do
Temporal.start_workflow(HelloWorldWorkflow, 'Test', options: {
workflow_id: workflow_id,
workflow_id_reuse_policy: :reject
})
end.to raise_error(Temporal::WorkflowExecutionAlreadyStartedFailure)
end
it 'terminates duplicate workflow ids based on workflow_id_reuse_policy' do
run_id_1 = Temporal.start_workflow(LongWorkflow, options: {
workflow_id: workflow_id,
workflow_id_reuse_policy: :terminate_if_running
})
run_id_2 = Temporal.start_workflow(LongWorkflow, options: {
workflow_id: workflow_id,
workflow_id_reuse_policy: :terminate_if_running
})
execution_1 = Temporal.fetch_workflow_execution_info(
Temporal.configuration.namespace,
workflow_id,
run_id_1)
execution_2 = Temporal.fetch_workflow_execution_info(
Temporal.configuration.namespace,
workflow_id,
run_id_2)
expect(execution_1.status).to eq(Temporal::Workflow::Status::TERMINATED)
expect(execution_2.status).to eq(Temporal::Workflow::Status::RUNNING)
end
end