Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit b58bc9e

Browse files
authored
Added explicit timeout to VES call (#22166)
* Added explicit timeout to VES call * Fixed reference to Common::Client::Base::Connection
1 parent be8b27a commit b58bc9e

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

modules/ivc_champva/lib/ves_api/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def submit_1010d(transaction_uuid, acting_user, ves_request_data)
3030
resp = connection.post("#{config.base_path}/champva-applications") do |req|
3131
req.headers = headers(transaction_uuid, acting_user)
3232
req.body = ves_request_data.to_json
33+
req.options = { timeout: 60 } # in seconds, anything lower than 5 will certainly cause problems
3334
end
3435

3536
monitor.track_ves_response(transaction_uuid, resp.status, resp.body)

modules/ivc_champva/spec/lib/ves_api_client_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'common/client/base'
34
require 'rails_helper'
45
require 'ves_api/client'
56

@@ -89,6 +90,31 @@
8990
end
9091
end
9192

93+
describe 'check options' do
94+
it 'sets the request timeout to at least 5 seconds' do
95+
# RuboCop prefers a constant class reference, but a string reference is necessary
96+
# because Common::Client::Base::Connection is private.
97+
# rubocop:disable RSpec/VerifiedDoubleReference
98+
connection = instance_double('Common::Client::Base::Connection') # Mock the private connection class
99+
# rubocop:enable RSpec/VerifiedDoubleReference
100+
response = instance_double(Faraday::Response, status: 200, body: '')
101+
allow(client).to receive(:connection).and_return(connection)
102+
103+
expect(connection).to receive(:post) do |&block|
104+
request = double(options: Faraday::RequestOptions.new)
105+
allow(request).to receive(:headers=)
106+
allow(request).to receive(:body=)
107+
allow(request).to receive(:options=) do |options|
108+
expect(options[:timeout]).to be > 5
109+
end
110+
block.call(request)
111+
response
112+
end
113+
114+
client.submit_1010d(transaction_uuid, acting_user, ves_request_data)
115+
end
116+
end
117+
92118
describe 'headers' do
93119
it 'returns the right headers' do
94120
result = client.headers('the_right_uuid', 'the_right_acting_user')

0 commit comments

Comments
 (0)