From 709a68ffb4a65922b1299a548a38079d5b914d1f Mon Sep 17 00:00:00 2001 From: svalexander Date: Tue, 30 Apr 2024 16:52:19 -0400 Subject: [PATCH 1/6] add faraday servererror to network errors --- app/jobs/risc_delivery_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/risc_delivery_job.rb b/app/jobs/risc_delivery_job.rb index b9d566335c0..fc52f2ae96b 100644 --- a/app/jobs/risc_delivery_job.rb +++ b/app/jobs/risc_delivery_job.rb @@ -6,6 +6,7 @@ class RiscDeliveryJob < ApplicationJob NETWORK_ERRORS = [ Faraday::TimeoutError, Faraday::ConnectionFailed, + Faraday::ServerError, Faraday::SSLError, Errno::ECONNREFUSED, ].freeze From d0a7b5b3ed96bb66d46cab7d1707c4032055d8a0 Mon Sep 17 00:00:00 2001 From: svalexander Date: Tue, 30 Apr 2024 17:24:00 -0400 Subject: [PATCH 2/6] move error to appropriate job --- app/jobs/risc_delivery_job.rb | 1 - app/jobs/usps_auth_token_refresh_job.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/jobs/risc_delivery_job.rb b/app/jobs/risc_delivery_job.rb index fc52f2ae96b..b9d566335c0 100644 --- a/app/jobs/risc_delivery_job.rb +++ b/app/jobs/risc_delivery_job.rb @@ -6,7 +6,6 @@ class RiscDeliveryJob < ApplicationJob NETWORK_ERRORS = [ Faraday::TimeoutError, Faraday::ConnectionFailed, - Faraday::ServerError, Faraday::SSLError, Errno::ECONNREFUSED, ].freeze diff --git a/app/jobs/usps_auth_token_refresh_job.rb b/app/jobs/usps_auth_token_refresh_job.rb index 0cc066b6268..483bdcc5110 100644 --- a/app/jobs/usps_auth_token_refresh_job.rb +++ b/app/jobs/usps_auth_token_refresh_job.rb @@ -7,7 +7,7 @@ def perform analytics.idv_usps_auth_token_refresh_job_started usps_proofer.retrieve_token! - rescue Faraday::TimeoutError, Faraday::ConnectionFailed => err + rescue Faraday::TimeoutError, Faraday::ConnectionFailed, Faraday::ServerError => err analytics.idv_usps_auth_token_refresh_job_network_error( exception_class: err.class.name, exception_message: err.message, From 7f0d2097fde98defcb0ab51d1b138bf28e343bdb Mon Sep 17 00:00:00 2001 From: svalexander Date: Wed, 1 May 2024 09:34:49 -0400 Subject: [PATCH 3/6] update refresh job spec to include server error --- spec/jobs/usps_auth_token_refresh_job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jobs/usps_auth_token_refresh_job_spec.rb b/spec/jobs/usps_auth_token_refresh_job_spec.rb index 02fb6bd0d6b..75c57ebfe56 100644 --- a/spec/jobs/usps_auth_token_refresh_job_spec.rb +++ b/spec/jobs/usps_auth_token_refresh_job_spec.rb @@ -86,7 +86,7 @@ end context 'auth request throws network error' do - [Faraday::TimeoutError, Faraday::ConnectionFailed].each do |err_class| + [Faraday::TimeoutError, Faraday::ServerError, Faraday::ConnectionFailed].each do |err_class| it "logs analytics without raising the #{err_class.name}" do stub_network_error_request_token( err_class.new('test error'), From 8401797994fe3a7f7e0eb19eef81b8a53ad551f5 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 1 May 2024 12:35:39 -0700 Subject: [PATCH 4/6] Use FakeAnalytics instead of stubbing to get clearer specs --- spec/jobs/usps_auth_token_refresh_job_spec.rb | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/spec/jobs/usps_auth_token_refresh_job_spec.rb b/spec/jobs/usps_auth_token_refresh_job_spec.rb index 75c57ebfe56..1b60f08184d 100644 --- a/spec/jobs/usps_auth_token_refresh_job_spec.rb +++ b/spec/jobs/usps_auth_token_refresh_job_spec.rb @@ -5,19 +5,13 @@ let(:subject) { described_class.new } let(:root_url) { 'http://my.root.url' } - let(:analytics) { instance_double(Analytics) } + let(:analytics) { FakeAnalytics.new } let(:usps_auth_token_cache_key) { UspsInPersonProofing::Proofer::AUTH_TOKEN_CACHE_KEY } before do allow(IdentityConfig.store).to receive(:usps_ipp_root_url).and_return(root_url) - allow(Analytics).to receive(:new). - with( - user: an_instance_of(AnonymousUser), - request: nil, - session: {}, - sp: nil, - ).and_return(analytics) + allow(subject).to receive(:analytics).and_return(analytics) end describe 'usps auth token refresh job' do @@ -69,19 +63,13 @@ end context 'auth request throws error' do - it 'still logs analytics' do + it 'catches server errors and logs them as network errors' do stub_error_request_token - expect(analytics).to receive( - :idv_usps_auth_token_refresh_job_started, - ).once - expect(analytics).to receive( - :idv_usps_auth_token_refresh_job_completed, - ).once + subject.perform - expect do - subject.perform - end.to raise_error + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Started') + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Network error') end end From bc4f62f987ed37ec2d0258a7a3ebf4f240a62bd9 Mon Sep 17 00:00:00 2001 From: svalexander Date: Wed, 1 May 2024 15:50:07 -0400 Subject: [PATCH 5/6] log job completed --- spec/jobs/usps_auth_token_refresh_job_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/jobs/usps_auth_token_refresh_job_spec.rb b/spec/jobs/usps_auth_token_refresh_job_spec.rb index 1b60f08184d..9f7cae055d4 100644 --- a/spec/jobs/usps_auth_token_refresh_job_spec.rb +++ b/spec/jobs/usps_auth_token_refresh_job_spec.rb @@ -70,6 +70,7 @@ expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Started') expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Network error') + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Completed') end end From 25f38e35eb2cb9afbf1e8ae0ee9c73b262fb30aa Mon Sep 17 00:00:00 2001 From: svalexander Date: Wed, 1 May 2024 16:57:36 -0400 Subject: [PATCH 6/6] changelog: Internal, UspsAuthTokenRefreshJob, rescue Faraday::ServerError