Skip to content

Commit

Permalink
Extract health check for depleted environments
Browse files Browse the repository at this point in the history
With the extracted method it is easier to recognize the environments which caused an issue in Sentry
  • Loading branch information
MrSerth authored and Dome-GER committed Sep 30, 2024
1 parent 9ee96ca commit db6edcd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/errors/runner/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class RunnerInUse < Error; end

class RunnerNotFound < Error; end

class PrewarmingPoolDepleted < Error; end

class FaradayError < Error; end

class UnexpectedResponse < Error; end
Expand Down
2 changes: 2 additions & 0 deletions lib/runner/strategy/poseidon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def self.health
case response.status
when 204
true
when 503
raise Runner::Error::PrewarmingPoolDepleted.new parse(response)[:message]
else
raise Runner::Error::UnexpectedResponse.new("Poseidon sent unexpected response status code #{response.status}")
end
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/runner/strategy/poseidon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,37 @@
end
end

describe '::health' do
let(:action) { -> { described_class.health } }
let(:faraday_connection) { instance_double Faraday::Connection }

before do
allow(described_class).to receive(:http_connection).and_return(faraday_connection)
end

it 'returns true when the api request was successful' do
allow(faraday_connection).to receive(:get).and_return(Faraday::Response.new(status: 204))
expect(action.call).to be_truthy
end

it 'raises an exception if Faraday raises an error' do
allow(faraday_connection).to receive(:get).and_raise(Faraday::TimeoutError)
expect { action.call }.to raise_exception Runner::Error::FaradayError
end

it 'raises an exception if Poseidon returns an error' do
allow(faraday_connection).to receive(:get).and_return(Faraday::Response.new(status: 500))
expect { action.call }.to raise_exception Runner::Error::UnexpectedResponse
end

it 'raises an exception if Poseidon reports a depleted prewarming pool' do
message = 'the prewarming pool is depleting: environments 10'
body = {message:, errorCode: 'PREWARMING_POOL_DEPLETING'}.to_json
allow(faraday_connection).to receive(:get).and_return(Faraday::Response.new(status: 503, body:))
expect { action.call }.to raise_exception Runner::Error::PrewarmingPoolDepleted, message
end
end

describe '::sync_environment' do
let(:action) { -> { described_class.sync_environment(execution_environment) } }
let(:execution_environment) { create(:ruby) }
Expand Down

0 comments on commit db6edcd

Please sign in to comment.