Skip to content

Commit 103213b

Browse files
use new Temporal client in interceptor test to avoid test pollution
1 parent b24bc6d commit 103213b

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

examples/spec/integration/interceptor_spec.rb

+25-11
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,37 @@ def request_response(request: nil, call: nil, method: nil, metadata: nil)
1414
end
1515
end
1616

17-
let(:interceptor) { ExampleInterceptor.new }
17+
def run_workflow_with_client(client, workflow, *input, **args)
18+
args[:options] = { workflow_id: SecureRandom.uuid }.merge(args[:options] || {})
19+
run_id = client.start_workflow(workflow, *input, **args)
1820

19-
around(:each) do |example|
20-
Temporal.configure do |config|
21-
config.interceptors = [interceptor]
22-
end
21+
[args[:options][:workflow_id], run_id]
22+
end
2323

24-
example.run
25-
ensure
26-
Temporal.configure do |config|
27-
config.interceptors = []
24+
let(:interceptor) { ExampleInterceptor.new }
25+
let(:config) do
26+
# We can't depend on test order here and the memoized
27+
# Temporal.default_client will not include our interceptors. Therefore we
28+
# build a new config and client based on the one used in the other tests.
29+
common_config = Temporal.configuration
30+
Temporal::Configuration.new.tap do |config|
31+
config.host = common_config.host
32+
config.port = common_config.port
33+
config.namespace = common_config.namespace
34+
config.task_queue = common_config.task_queue
35+
config.metrics_adapter = common_config.metrics_adapter
36+
config.interceptors = [interceptor]
2837
end
2938
end
39+
let(:client) { Temporal::Client.new(config) }
3040

3141
it 'calls the given interceptors when performing operations' do
32-
workflow_id, run_id = run_workflow(HelloWorldWorkflow, 'Tom')
33-
wait_for_workflow_completion(workflow_id, run_id)
42+
workflow_id, run_id = run_workflow_with_client(client, HelloWorldWorkflow, 'Tom')
43+
client.await_workflow_result(
44+
HelloWorldWorkflow,
45+
workflow_id: workflow_id,
46+
run_id: run_id
47+
)
3448

3549
expect(interceptor.called_methods).to match_array([
3650
"/temporal.api.workflowservice.v1.WorkflowService/StartWorkflowExecution",

0 commit comments

Comments
 (0)