forked from coinbase/temporal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_workflow_spec.rb
59 lines (44 loc) · 2.68 KB
/
query_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
require 'workflows/query_workflow'
require 'temporal/errors'
describe QueryWorkflow, :integration do
subject { described_class }
it 'returns the correct result for the queries' do
workflow_id, run_id = run_workflow(described_class)
# Query with nil workflow class
expect(Temporal.query_workflow(nil, 'state', workflow_id, run_id))
.to eq 'started'
# Query with arbitrary args
expect(Temporal.query_workflow(described_class, 'state', workflow_id, run_id,
'upcase', 'ignored', 'reverse'))
.to eq 'DETRATS'
# Query with no args
expect(Temporal.query_workflow(described_class, 'signal_count', workflow_id, run_id))
.to eq 0
# Query with unregistered handler
expect { Temporal.query_workflow(described_class, 'unknown_query', workflow_id, run_id) }
.to raise_error(Temporal::QueryFailed, "Workflow did not register a handler for 'unknown_query'. KnownQueryTypes=[__stack_trace, state, signal_count]")
# Query built-in stack trace handler, looking for a couple of key parts of the contents
stack_trace = Temporal.query_workflow(described_class, '__stack_trace', workflow_id, run_id)
expect(stack_trace).to start_with "Fiber count: 1\n\n"
expect(stack_trace).to include "/examples/workflows/query_workflow.rb:"
Temporal.signal_workflow(described_class, 'make_progress', workflow_id, run_id)
# Query for updated signal_count with an unsatisfied reject condition
expect(Temporal.query_workflow(described_class, 'signal_count', workflow_id, run_id, query_reject_condition: :not_open))
.to eq 1
Temporal.signal_workflow(described_class, 'finish', workflow_id, run_id)
wait_for_workflow_completion(workflow_id, run_id)
# Repeating original query scenarios above, expecting updated state and signal results
expect(Temporal.query_workflow(nil, 'state', workflow_id, run_id))
.to eq 'finished'
expect(Temporal.query_workflow(described_class, 'state', workflow_id, run_id,
'upcase', 'ignored', 'reverse'))
.to eq 'DEHSINIF'
expect(Temporal.query_workflow(described_class, 'signal_count', workflow_id, run_id))
.to eq 2
expect { Temporal.query_workflow(described_class, 'unknown_query', workflow_id, run_id) }
.to raise_error(Temporal::QueryFailed, "Workflow did not register a handler for 'unknown_query'. KnownQueryTypes=[__stack_trace, state, signal_count]")
# Now that the workflow is completed, test a query with a reject condition satisfied
expect { Temporal.query_workflow(described_class, 'state', workflow_id, run_id, query_reject_condition: :not_open) }
.to raise_error(Temporal::QueryFailed, 'Query rejected: status WORKFLOW_EXECUTION_STATUS_COMPLETED')
end
end