Skip to content

Commit

Permalink
Merge pull request #1774 from DFE-Digital/dfe-healthcheck-timeouts
Browse files Browse the repository at this point in the history
Handle gracefully the dfe sign in healthchecks
  • Loading branch information
leoapost authored Jun 18, 2021
2 parents a4e3dd5 + bd336e8 commit bf8fc8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_dfe_signin_api
return true unless Schools::DFESignInAPI::Organisations.enabled?

Schools::DFESignInAPI::Organisations.new(SecureRandom.uuid).uuids
rescue RuntimeError
rescue RuntimeError, Rack::Timeout::RequestTimeoutException
false
end

Expand Down
5 changes: 4 additions & 1 deletion app/services/schools/dfe_sign_in_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class APIResponseError < RuntimeError; end

class Client
TIMEOUT_SECS = 15
RETRY_EXCEPTIONS = [::Faraday::ConnectionFailed].freeze
RETRY_EXCEPTIONS = [
::Faraday::ConnectionFailed,
Rack::Timeout::RequestTimeoutException
].freeze
RETRY_OPTIONS = {
max: 2,
methods: %i[get],
Expand Down
16 changes: 9 additions & 7 deletions spec/models/healthcheck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,27 @@

describe "#test_dfe_signin_api" do
before do
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:enabled?).and_return(false)
allow(Schools::DFESignInAPI::Organisations).to receive(:enabled?).and_return(true)
end

subject { described_class.new.test_dfe_signin_api }

context "with working connection" do
before do
allow(Schools::DFESignInAPI::Organisations).to receive(:uuids).and_return([])
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:uuids).and_return({})
end

xit { is_expected.to be true }
it { is_expected.to be_a Hash }
end

context "with non functional connection" do
before do
allow(Schools::DFESignInAPI::Client).to receive(:response).and_raise Faraday::TimeoutError
end
it "returns false" do
[RuntimeError, Redis::CannotConnectError].each do |error|
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:response).and_raise error

xit { is_expected.to be false }
is_expected.to be false
end
end
end

context "with no configured connection" do
Expand Down

0 comments on commit bf8fc8c

Please sign in to comment.