From 98abce95b6569f78adfcea7bdf2320e37432af97 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:29:02 +0100 Subject: [PATCH 1/2] Revert "Avoid timeouts for batch requests" This reverts commit 2f030f0f70844634ab2db335b4bb4fd7b73a406a. --- lib/profile_api_client.rb | 21 +++------ spec/lib/profile_api_client_spec.rb | 44 ------------------- .../profile_api_client_examples.rb | 16 ------- 3 files changed, 5 insertions(+), 76 deletions(-) diff --git a/lib/profile_api_client.rb b/lib/profile_api_client.rb index b19dbef78..d02119fad 100644 --- a/lib/profile_api_client.rb +++ b/lib/profile_api_client.rb @@ -111,7 +111,7 @@ def validate_school_students(token:, students:, school_id:) students = Array(students) endpoint = "/api/v1/schools/#{school_id}/students/preflight-student-upload" - response = connection(token, connection_options_for_slow_requests).post(endpoint) do |request| + response = connection(token).post(endpoint) do |request| request.body = students.to_json request.headers['Content-Type'] = 'application/json' end @@ -128,7 +128,7 @@ def create_school_students(token:, students:, school_id:, preflight: false) students = Array(students) endpoint = "/api/v1/schools/#{school_id}/students" endpoint += '/preflight' if preflight - response = connection(token, connection_options_for_slow_requests).post(endpoint) do |request| + response = connection(token).post(endpoint) do |request| request.body = students.to_json request.headers['Content-Type'] = 'application/json' end @@ -146,7 +146,7 @@ def create_school_students_sso(token:, students:, school_id:) students = Array(students) endpoint = "/api/v1/schools/#{school_id}/students/sso" - response = connection(token, connection_options_for_slow_requests).post(endpoint) do |request| + response = connection(token).post(endpoint) do |request| request.body = students.to_json request.headers['Content-Type'] = 'application/json' end @@ -220,8 +220,8 @@ def update_school_email_domains(token:, school_id:, school_email_domains: []) private - def connection(token, options = {}) - HttpClient.new(ENV.fetch('IDENTITY_URL'), options) do |faraday| + def connection(token) + HttpClient.new(ENV.fetch('IDENTITY_URL')) do |faraday| faraday.request :json faraday.response :json faraday.response :raise_error, allowed_statuses: [401] @@ -263,16 +263,5 @@ def unauthorized!(response) # The API is only available to verified non-student users that are over 13. Others get a 401. raise UnauthorizedError, 'Profile API unauthorized' if response.status == 401 end - - def connection_options_for_slow_requests - { - request: { - read_timeout: 50, - open_timeout: 5, - write_timeout: 5, - timeout: 50 - } - } - end end end diff --git a/spec/lib/profile_api_client_spec.rb b/spec/lib/profile_api_client_spec.rb index 53a497e1e..1033baab1 100644 --- a/spec/lib/profile_api_client_spec.rb +++ b/spec/lib/profile_api_client_spec.rb @@ -228,48 +228,6 @@ def create_school_student end end - describe '.validate_school_students' do - subject(:validate_school_students_response) { validate_school_students } - - let(:students) { [{ name: 'name', username: 'username', password: 'password' }] } - let(:school) { build(:school, id: SecureRandom.uuid) } - let(:validate_students_url) { "#{api_url}/api/v1/schools/#{school.id}/students/preflight-student-upload" } - - before do - stub_request(:post, validate_students_url).to_return(status: 200, body: '{}', headers: { 'content-type' => 'application/json' }) - end - - it_behaves_like 'an authenticated JSON API request', :post, url: -> { validate_students_url } - it_behaves_like 'a request that handles standard HTTP errors', :post, url: -> { validate_students_url } - it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { validate_students_url }, status: 201 - it_behaves_like 'a request that allows longer for a response' - - it 'sends the student details in the request body' do - validate_school_students_response - expect(WebMock).to have_requested(:post, validate_students_url).with(body: students.to_json) - end - - it 'raises 422 exception with the validation errors if 422 status code is returned' do - response = { errors: [{ message: 'The password is well dodgy' }] } - stub_request(:post, validate_students_url) - .to_return(status: 422, body: response.to_json, headers: { 'content-type' => 'application/json' }) - - expect { validate_school_students }.to raise_error(ProfileApiClient::Student422Error) do |error| - expect(error.errors.first['message']).to eq('The password is well dodgy') - end - end - - it 'returns nil if token is blank' do - expect(described_class.validate_school_students(token: '', students:, school_id: school.id)).to be_nil - end - - private - - def validate_school_students - described_class.validate_school_students(token:, students:, school_id: school.id) - end - end - describe '.create_school_students' do subject(:create_school_students_response) { create_school_students } @@ -287,7 +245,6 @@ def validate_school_students it_behaves_like 'an authenticated JSON API request', :post, url: -> { create_students_url } it_behaves_like 'a request that handles standard HTTP errors', :post, url: -> { create_students_url } it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { create_students_url }, status: 202 - it_behaves_like 'a request that allows longer for a response' it 'raises 422 exception with the relevant message if 400 status code is returned' do response = { errors: [{ message: 'The password is well dodgy' }] } @@ -360,7 +317,6 @@ def create_school_students it_behaves_like 'an authenticated JSON API request', :post, url: -> { create_students_sso_url } it_behaves_like 'a request that handles standard HTTP errors', :post, url: -> { create_students_sso_url } it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { create_students_sso_url }, status: 202 - it_behaves_like 'a request that allows longer for a response' it 'raises 422 exception with the relevant message if 400 status code is returned' do response = { errors: [{ message: 'The password is well dodgy' }] } diff --git a/spec/support/shared_examples/profile_api_client_examples.rb b/spec/support/shared_examples/profile_api_client_examples.rb index 7b64754dd..9a89e7a20 100644 --- a/spec/support/shared_examples/profile_api_client_examples.rb +++ b/spec/support/shared_examples/profile_api_client_examples.rb @@ -73,19 +73,3 @@ expect { subject }.to raise_error(ProfileApiClient::UnexpectedResponse) end end - -RSpec.shared_examples 'a request that allows longer for a response' do - let(:faraday_connections) { [] } - - before do - connections = faraday_connections - allow(HttpClient).to receive(:new).and_wrap_original do |original_method, *args, &block| - original_method.call(*args, &block).tap { |connection| connections << connection } - end - end - - it 'gives the profile api longer to respond than the default timeouts allow' do - subject - expect(faraday_connections.last.options).to have_attributes(open_timeout: 5, write_timeout: 5, read_timeout: 50, timeout: 50) - end -end From 1fe0bbeaa1cb09e2a26ae769481fa384d5229eb2 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:29:30 +0100 Subject: [PATCH 2/2] Revert "Configure timeouts HTTP requests" This reverts commit 6acc4d714b4caf0abac1a9e4e72271623cb79108. --- lib/http_client.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/http_client.rb b/lib/http_client.rb index 686c8fa53..01d702298 100644 --- a/lib/http_client.rb +++ b/lib/http_client.rb @@ -4,17 +4,6 @@ module HttpClient def self.new(url = nil, options = {}) - default_options = { - request: { - read_timeout: 5, - open_timeout: 5, - write_timeout: 5, - timeout: 10 - } - } - - options = default_options.deep_merge(options) - Faraday.new(url, options) do |f| f.use RecordRequestHostInErrors yield f