DCP: Change HTTP verbs
This commit is contained in:
@ -22,7 +22,8 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
||||
def self.request_from_management(environment)
|
||||
url = "#{config[:url]}/docker_container_pool/get_container/#{environment.id}"
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Requesting new runner at #{url}" }
|
||||
response = Faraday.get url
|
||||
response = Faraday.post url, body
|
||||
|
||||
container_id = JSON.parse(response.body)['id']
|
||||
container_id.presence || raise(Runner::Error::NotAvailable.new("DockerContainerPool didn't return a container id"))
|
||||
rescue Faraday::Error => e
|
||||
@ -36,7 +37,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
||||
def destroy_at_management
|
||||
url = "#{self.class.config[:url]}/docker_container_pool/destroy_container/#{container.id}"
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Destroying runner at #{url}" }
|
||||
Faraday.get(url)
|
||||
Faraday.delete(url)
|
||||
rescue Faraday::Error => e
|
||||
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
|
||||
ensure
|
||||
|
@ -8,7 +8,7 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
let(:execution_environment) { FactoryBot.create :ruby }
|
||||
let(:container_pool) { described_class.new(runner_id, execution_environment) }
|
||||
let(:docker_container_pool_url) { 'http://localhost:1234' }
|
||||
let(:config) { {pool: {location: docker_container_pool_url}} }
|
||||
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
|
||||
let(:container) { instance_double(Docker::Container) }
|
||||
|
||||
before do
|
||||
@ -17,9 +17,9 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
end
|
||||
|
||||
# All requests handle a Faraday error the same way.
|
||||
shared_examples 'Faraday error handling' do
|
||||
shared_examples 'Faraday error handling' do |http_verb|
|
||||
it 'raises a runner error' do
|
||||
allow(Faraday).to receive(:get).and_raise(Faraday::TimeoutError)
|
||||
allow(Faraday).to receive(http_verb).and_raise(Faraday::TimeoutError)
|
||||
expect { action.call }.to raise_error(Runner::Error::FaradayError)
|
||||
end
|
||||
end
|
||||
@ -29,7 +29,7 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
let(:response_body) { nil }
|
||||
let!(:request_runner_stub) do
|
||||
WebMock
|
||||
.stub_request(:get, "#{docker_container_pool_url}/docker_container_pool/get_container/#{execution_environment.id}")
|
||||
.stub_request(:post, "#{docker_container_pool_url}/docker_container_pool/get_container/#{execution_environment.id}")
|
||||
.to_return(body: response_body, status: 200)
|
||||
end
|
||||
|
||||
@ -63,14 +63,14 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
end
|
||||
end
|
||||
|
||||
include_examples 'Faraday error handling'
|
||||
include_examples 'Faraday error handling', :post
|
||||
end
|
||||
|
||||
describe '#destroy_at_management' do
|
||||
let(:action) { -> { container_pool.destroy_at_management } }
|
||||
let!(:destroy_runner_stub) do
|
||||
WebMock
|
||||
.stub_request(:get, "#{docker_container_pool_url}/docker_container_pool/destroy_container/#{runner_id}")
|
||||
.stub_request(:delete, "#{docker_container_pool_url}/docker_container_pool/destroy_container/#{runner_id}")
|
||||
.to_return(body: nil, status: 200)
|
||||
end
|
||||
|
||||
@ -81,7 +81,7 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
expect(destroy_runner_stub).to have_been_requested.once
|
||||
end
|
||||
|
||||
include_examples 'Faraday error handling'
|
||||
include_examples 'Faraday error handling', :delete
|
||||
end
|
||||
|
||||
describe '#copy_files' do
|
||||
|
Reference in New Issue
Block a user