-
Notifications
You must be signed in to change notification settings - Fork 89
/
named_signal_handler_spec.rb
84 lines (67 loc) · 2.72 KB
/
named_signal_handler_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
require 'workflows/wait_for_named_signal_workflow'
describe WaitForNamedSignalWorkflow, :integration do
let(:receiver_workflow_id) { SecureRandom.uuid }
context 'when the signal is named' do
let(:arg1) { "arg1" }
let(:arg2) { 7890.1234 }
context 'and the workflow has a named signal handler matching the signal name' do
let(:signal_name) { "NamedSignal" }
it 'receives the signal in its named handler' do
_, run_id = run_workflow(WaitForNamedSignalWorkflow, signal_name, options: { workflow_id: receiver_workflow_id})
Temporal.signal_workflow(WaitForNamedSignalWorkflow, signal_name, receiver_workflow_id, run_id, [arg1, arg2])
result = Temporal.await_workflow_result(
WaitForNamedSignalWorkflow,
workflow_id: receiver_workflow_id,
run_id: run_id,
)
expect(result[:received]).to include({signal_name => [arg1, arg2]})
expect(result[:counts]).to include({signal_name => 1})
expect(result).to eq(
{
received: {
signal_name => [arg1, arg2],
'catch-all' => [arg1, arg2]
},
counts: {
signal_name => 1,
'catch-all' => 1
}
}
)
end
it 'receives the signal in its catch-all signal handler' do
_, run_id = run_workflow(WaitForNamedSignalWorkflow, signal_name, options: { workflow_id: receiver_workflow_id})
Temporal.signal_workflow(WaitForNamedSignalWorkflow, signal_name, receiver_workflow_id, run_id, [arg1, arg2])
result = Temporal.await_workflow_result(
WaitForNamedSignalWorkflow,
workflow_id: receiver_workflow_id,
run_id: run_id,
)
expect(result[:received]).to include({"catch-all" => [arg1, arg2]})
expect(result[:counts]).to include({"catch-all" => 1})
end
end
context 'and the workflow does NOT have a named signal handler matching the signal name' do
let(:signal_name) { 'doesNOTmatchAsignalHandler' }
it 'receives the signal in its catch-all signal handler' do
_, run_id = run_workflow(WaitForNamedSignalWorkflow, signal_name, options: { workflow_id: receiver_workflow_id})
Temporal.signal_workflow(WaitForNamedSignalWorkflow, signal_name, receiver_workflow_id, run_id, [arg1, arg2])
result = Temporal.await_workflow_result(
WaitForNamedSignalWorkflow,
workflow_id: receiver_workflow_id,
run_id: run_id,
)
expect(result).to eq(
{
received: {
'catch-all' => [arg1, arg2]
},
counts: {
'catch-all' => 1
}
}
)
end
end
end
end