forked from coinbase/temporal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_workflow_spec.rb
163 lines (134 loc) · 4.86 KB
/
reset_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require 'workflows/hello_world_workflow'
require 'workflows/query_workflow'
require 'temporal/reset_reapply_type'
describe 'Temporal.reset_workflow' do
it 'can reset a closed workflow to the beginning' do
workflow_id = SecureRandom.uuid
original_run_id = Temporal.start_workflow(
HelloWorldWorkflow,
'Test',
options: { workflow_id: workflow_id }
)
original_result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: original_run_id
)
expect(original_result).to eq('Hello World, Test')
new_run_id = Temporal.reset_workflow(
Temporal.configuration.namespace,
workflow_id,
original_run_id,
strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK
)
new_result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: new_run_id,
)
expect(new_result).to eq('Hello World, Test')
end
def reset_hello_world_workflow_twice(workflow_id, original_run_id, request_id:)
2.times.map do
new_run_id = Temporal.reset_workflow(
Temporal.configuration.namespace,
workflow_id,
original_run_id,
strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK,
request_id: request_id
)
new_result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: new_run_id,
)
expect(new_result).to eq('Hello World, Test')
new_run_id
end
end
it 'can repeatedly reset the same closed workflow to the beginning' do
workflow_id = SecureRandom.uuid
original_run_id = Temporal.start_workflow(
HelloWorldWorkflow,
'Test',
options: { workflow_id: workflow_id }
)
original_result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: original_run_id,
)
expect(original_result).to eq('Hello World, Test')
new_run_ids = reset_hello_world_workflow_twice(
workflow_id,
original_run_id,
# This causes the request_id to be generated with a random value:
request_id: nil
)
# Each Reset request should have resulted in a unique workflow execution
expect(new_run_ids.uniq.size).to eq(new_run_ids.size)
end
it 'can deduplicate reset requests' do
workflow_id = SecureRandom.uuid
original_run_id = Temporal.start_workflow(
HelloWorldWorkflow,
'Test',
options: { workflow_id: workflow_id }
)
original_result = Temporal.await_workflow_result(
HelloWorldWorkflow,
workflow_id: workflow_id,
run_id: original_run_id,
)
expect(original_result).to eq('Hello World, Test')
reset_request_id = SecureRandom.uuid
new_run_ids = reset_hello_world_workflow_twice(
workflow_id,
original_run_id,
request_id: reset_request_id
)
# Each Reset request except the first should have been deduplicated
expect(new_run_ids.uniq.size).to eq(1)
end
def start_query_workflow_and_signal_three_times
workflow_id = SecureRandom.uuid
run_id = Temporal.start_workflow(
QueryWorkflow,
options: { workflow_id: workflow_id }
)
expect(Temporal.query_workflow(QueryWorkflow, 'signal_count', workflow_id, run_id))
.to eq 0
Temporal.signal_workflow(QueryWorkflow, 'make_progress', workflow_id, run_id)
Temporal.signal_workflow(QueryWorkflow, 'make_progress', workflow_id, run_id)
Temporal.signal_workflow(QueryWorkflow, 'make_progress', workflow_id, run_id)
expect(Temporal.query_workflow(QueryWorkflow, 'signal_count', workflow_id, run_id))
.to eq 3
{ workflow_id: workflow_id, run_id: run_id }
end
it 'can reapply signals when resetting a workflow' do
workflow_id, original_run_id = start_query_workflow_and_signal_three_times.values_at(:workflow_id, :run_id)
new_run_id = Temporal.reset_workflow(
Temporal.configuration.namespace,
workflow_id,
original_run_id,
strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK,
reset_reapply_type: Temporal::ResetReapplyType::SIGNAL
)
expect(Temporal.query_workflow(QueryWorkflow, 'signal_count', workflow_id, new_run_id))
.to eq 3
Temporal.terminate_workflow(workflow_id, run_id: new_run_id)
end
it 'can skip reapplying signals when resetting a workflow' do
workflow_id, original_run_id = start_query_workflow_and_signal_three_times.values_at(:workflow_id, :run_id)
new_run_id = Temporal.reset_workflow(
Temporal.configuration.namespace,
workflow_id,
original_run_id,
strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK,
reset_reapply_type: Temporal::ResetReapplyType::NONE
)
expect(Temporal.query_workflow(QueryWorkflow, 'signal_count', workflow_id, new_run_id))
.to eq 0
Temporal.terminate_workflow(workflow_id, run_id: new_run_id)
end
end