summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Hu <huh@vmware.com>2014-09-04 16:57:32 +0800
committerHui Hu <huh@vmware.com>2014-09-04 16:57:32 +0800
commit3d3aa968f88ed27dcaf19aa82c730cf34cce7441 (patch)
treef3cf6123bc5a3c463135f51bb9732dd7f01de7b9
parentace6c1e64fa32efcb9beeb8238edb1d71dab659d (diff)
downloadchef-3d3aa968f88ed27dcaf19aa82c730cf34cce7441.tar.gz
read http_retry_count from chef config in the spec; add HTTP error code in the log.
-rw-r--r--lib/chef/http.rb2
-rw-r--r--spec/unit/rest_spec.rb5
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index bdfd30f140..7f2d00157b 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -296,7 +296,7 @@ class Chef
if response.kind_of?(Net::HTTPServerError)
if http_retry_count - http_attempts + 1 > 0
sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts)
- Chef::Log.error("Server returned error for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
+ Chef::Log.error("Server returned error #{response.code} for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
sleep(sleep_time)
redo
end
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index f82e4f5472..4d4dccaba6 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -527,10 +527,11 @@ describe Chef::REST do
http_response
end
- it "retries 5 times and throws an exception" do
+ it "retries then throws an exception" do
rest.stub(:sleep)
expect {rest.request(:GET, url)}.to raise_error(Net::HTTPFatalError)
- expect(log_stringio.string).to match(Regexp.escape("ERROR: Server returned error for #{url}, retrying 5/5"))
+ count = Chef::Config[:http_retry_count]
+ expect(log_stringio.string).to match(Regexp.escape("ERROR: Server returned error 500 for #{url}, retrying #{count}/#{count}"))
end
end
end