-
Notifications
You must be signed in to change notification settings - Fork 166
LG-13191 rescue faraday servererror #10533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
709a68f
d0a7b5b
7f0d209
8401797
bc4f62f
25f38e3
eb8fb68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,24 +63,19 @@ | |
| 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') | ||
| expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Completed') | ||
| end | ||
| 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| | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zachmargolis I'm wondering how i can test this to confirm that #login-alarms wouldnt be alerted
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alarms go off when the jobs have unhandled exceptions, so by handling the exception (and the |
||
| it "logs analytics without raising the #{err_class.name}" do | ||
| stub_network_error_request_token( | ||
| err_class.new('test error'), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't select it, but I'd expect the test above to error -- if we're catching a
ServerError, this should fail:because there is no error being thrown
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see what you're saying, it is passing though which is curious. I;m trying to figure out why this is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you take off the
expect { ... }.to_not raise_erroryou see that it's throwing an error for a method expectation based on a different logging method called.so it's technically still throwing an error and the spec technically passes.
If the test was originally written to say
expect { ... }.to_not raise_error(Faraday::ServerError)then it would have been a clearer failure hereUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when i update the test to
...to_not raise_error(Faraday::ServerError)to check what happens it passesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes with
to_not raise_error(Faraday::ServerError)because gets this error instead from the stubI pushed 8401797 to switch out the
instance_doublefor aFakeAnalyticsinstance which is a better fake logger and has clearer spec failures when the rescue forFaraday::ServerErroris removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh ok that makes sense! i think we still need the completion log, I'll add it in. Thanks for making this change!