-
Notifications
You must be signed in to change notification settings - Fork 89
/
continue_as_new_spec.rb
93 lines (82 loc) · 2.48 KB
/
continue_as_new_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
require 'workflows/continue_as_new_workflow'
require 'workflows/loop_workflow'
describe LoopWorkflow do
it 'workflow continues as new into a new run' do
workflow_id = SecureRandom.uuid
memo = {
'my-memo' => 'foo',
}
headers = {
'my-header' => 'bar',
'test-header' => 'test',
}
run_id = Temporal.start_workflow(
LoopWorkflow,
2, # it continues as new if this arg is > 1
options: {
workflow_id: workflow_id,
memo: memo,
headers: headers,
},
)
# First run will throw because it continued as new
next_run_id = nil
expect do
Temporal.await_workflow_result(
LoopWorkflow,
workflow_id: workflow_id,
run_id: run_id,
)
end.to raise_error(Temporal::WorkflowRunContinuedAsNew) do |error|
next_run_id = error.new_run_id
end
expect(next_run_id).to_not eq(nil)
# Second run will not throw because it returns rather than continues as new.
final_result = Temporal.await_workflow_result(
LoopWorkflow,
workflow_id: workflow_id,
run_id: next_run_id,
)
expect(final_result[:count]).to eq(1)
# memo and headers should be copied to the next run automatically
expect(final_result[:memo]).to eq(memo)
expect(final_result[:headers]).to eq(headers)
end
it 'uses history bytes size to continue as new' do
workflow_id = SecureRandom.uuid
# 7 activity invocations produce about 10,000 bytes of history. This should
# result in one continue as new with 7 activities in the first and 3 in the
# second run.
run_id = Temporal.start_workflow(
ContinueAsNewWorkflow,
10, # hello count
10_000, # max bytes limit
options: {
workflow_id: workflow_id,
timeouts: {
execution: 60,
run: 20
}
},
)
# First run will throw because it continued as new
next_run_id = nil
expect do
Temporal.await_workflow_result(
ContinueAsNewWorkflow,
workflow_id: workflow_id,
run_id: run_id,
)
end.to raise_error(Temporal::WorkflowRunContinuedAsNew) do |error|
next_run_id = error.new_run_id
end
expect(next_run_id).to_not eq(nil)
# Second run will not throw because it returns rather than continues as new.
final_result = Temporal.await_workflow_result(
ContinueAsNewWorkflow,
workflow_id: workflow_id,
run_id: next_run_id,
)
expect(final_result[:runs]).to eq(2)
end
end