From 56eab88f8866c96ddb900853ff40d3031ddeb0b8 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 15 Jul 2022 00:35:43 +0200 Subject: [PATCH] Gracefully handle the deletion of non-existing runners --- lib/runner/strategy/poseidon.rb | 2 ++ spec/lib/runner/strategy/poseidon_spec.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/runner/strategy/poseidon.rb b/lib/runner/strategy/poseidon.rb index e6d68de7..2991aa34 100644 --- a/lib/runner/strategy/poseidon.rb +++ b/lib/runner/strategy/poseidon.rb @@ -101,6 +101,8 @@ class Runner::Strategy::Poseidon < Runner::Strategy Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Destroying runner at #{runner_url}" } response = self.class.http_connection.delete runner_url self.class.handle_error response unless response.status == 204 + rescue Runner::Error::RunnerNotFound + Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Runner not found, nothing to destroy" } rescue Faraday::Error => e raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}") ensure diff --git a/spec/lib/runner/strategy/poseidon_spec.rb b/spec/lib/runner/strategy/poseidon_spec.rb index 73259815..e3e24c26 100644 --- a/spec/lib/runner/strategy/poseidon_spec.rb +++ b/spec/lib/runner/strategy/poseidon_spec.rb @@ -312,8 +312,15 @@ describe Runner::Strategy::Poseidon do end end + context 'when Poseidon returns NotFound (404)' do + let(:response_status) { 404 } + + it 'raises an error' do + expect { action.call }.not_to raise_error(Runner::Error::RunnerNotFound) + end + end + include_examples 'Unauthorized (401) error handling' - include_examples 'NotFound (404) error handling' include_examples 'InternalServerError (500) error handling' include_examples 'unknown response status error handling' include_examples 'Faraday error handling'