Skip to content
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

Wait longer for docker to kill containers during stop/restart #175

Merged
merged 2 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion centurion.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'logger-colors'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rake', '~> 10.5'
spec.add_development_dependency 'rspec', '~> 3.1.0'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'simplecov'
Expand Down
10 changes: 8 additions & 2 deletions lib/centurion/docker_via_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def stop_container(container_id, timeout = 30)
response = Excon.post(
@base_uri + path,
tls_excon_arguments.merge(
read_timeout: timeout
# Wait for both the docker stop timeout AND the kill AND
# potentially a very slow HTTP server.
read_timeout: timeout + 120
)
)
raise response.inspect unless response.status == 204
Expand Down Expand Up @@ -94,7 +96,11 @@ def restart_container(container_id, timeout = 30)
path = @docker_api_version + "/containers/#{container_id}/restart?t=#{timeout}"
response = Excon.post(
@base_uri + path,
tls_excon_arguments
tls_excon_arguments.merge(
# Wait for both the docker stop timeout AND the kill AND
# potentially a very slow HTTP server.
read_timeout: timeout + 120
)
)
case response.status
when 204
Expand Down
2 changes: 1 addition & 1 deletion lib/centurion/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Centurion
VERSION = '1.8.7'
VERSION = '1.8.8'
end
19 changes: 11 additions & 8 deletions spec/docker_via_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,29 @@

it 'stops a container' do
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/stop?t=300", {read_timeout: 300}).
with(excon_uri + "v1.12" + "/containers/12345/stop?t=300", {read_timeout: 420}).
and_return(double(status: 204))
api.stop_container('12345', 300)
end

it 'stops a container with a custom timeout' do
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/stop?t=30", {read_timeout: 30}).
with(excon_uri + "v1.12" + "/containers/12345/stop?t=30", {read_timeout: 150}).
and_return(double(status: 204))
api.stop_container('12345')
end

it 'restarts a container' do
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=30", {}).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=30",
{read_timeout: 150}).
and_return(double(body: json_string, status: 204))
api.restart_container('12345')
end

it 'restarts a container with a custom timeout' do
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=300", {}).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=300", {:read_timeout=>420}).
and_return(double(body: json_string, status: 204))
api.restart_container('12345', 300)
end
Expand Down Expand Up @@ -179,7 +180,7 @@
with(excon_uri + "v1.12" + "/containers/12345/stop?t=300",
client_cert: '/certs/cert.pem',
client_key: '/certs/key.pem',
read_timeout: 300).
read_timeout: 420).
and_return(double(status: 204))
api.stop_container('12345', 300)
end
Expand All @@ -189,7 +190,7 @@
with(excon_uri + "v1.12" + "/containers/12345/stop?t=30",
client_cert: '/certs/cert.pem',
client_key: '/certs/key.pem',
read_timeout: 30).
read_timeout: 150).
and_return(double(status: 204))
api.stop_container('12345')
end
Expand All @@ -198,7 +199,8 @@
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=30",
client_cert: '/certs/cert.pem',
client_key: '/certs/key.pem').
client_key: '/certs/key.pem',
read_timeout: 150).
and_return(double(body: json_string, status: 204))
api.restart_container('12345')
end
Expand All @@ -207,7 +209,8 @@
expect(Excon).to receive(:post).
with(excon_uri + "v1.12" + "/containers/12345/restart?t=300",
client_cert: '/certs/cert.pem',
client_key: '/certs/key.pem').
client_key: '/certs/key.pem',
read_timeout: 420).
and_return(double(body: json_string, status: 204))
api.restart_container('12345', 300)
end
Expand Down