summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hinderliter <tim@opscode.com>2010-11-05 16:53:44 -0700
committerTim Hinderliter <tim@opscode.com>2010-11-05 17:06:57 -0700
commit2dc5496f59856b04f562e36d6ec187328cfd5eba (patch)
tree55372a5c1f5e7a76a5971ee8213ce71aa1489308
parentbd32a4e17573b5821a3dd5f5137cd6808f0306e2 (diff)
downloadchef-2dc5496f59856b04f562e36d6ec187328cfd5eba.tar.gz
Fix CHEF-1851: in features tests, on creating right couch db
chef_integration right after deleting, we sometimes get a 412 due to a Couch bug. Retry up to 10 times as this issue goes away (same fix as for couchdb_replicate work)
-rw-r--r--features/support/env.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/features/support/env.rb b/features/support/env.rb
index 5cb8958498..652169a2b6 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -80,7 +80,40 @@ end
def create_databases
Chef::Log.info("Creating bootstrap databases")
cdb = Chef::CouchDB.new(Chef::Config[:couchdb_url], "chef_integration")
- cdb.create_db
+
+ # Sometimes Couch returns a '412 Precondition Failed' when creating a database,
+ # via a PUT to its URL, as the DELETE from the previous step in delete_databases
+ # has not yet finished. This condition disappears if you try again. So here we
+ # try up to 10 times if PreconditionFailed occurs. See
+ # http://tickets.opscode.com/browse/CHEF-1788 and
+ # http://tickets.opscode.com/browse/CHEF-1764.
+ #
+ # According to https://issues.apache.org/jira/browse/COUCHDB-449, setting the
+ # 'X-Couch-Full-Commit: true' header on the DELETE should work around this issue,
+ # but it does not.
+ db_created = nil
+ max_tries = 10
+ num_tries = 1
+ while !db_created && num_tries <= max_tries
+ begin
+ cdb.create_db
+ db_created = true
+ rescue Net::HTTPServerException => e
+ unless e.response.code == 412
+ # Re-raise if we got anything but 412.
+ raise
+ end
+
+ if num_tries <= max_tries
+ Chef::Log.debug("In creating #{target_db} try #{num_tries}/#{max_tries}, got #{e}; try again")
+ sleep 0.25
+ else
+ Chef::Log.error("In creating #{target_db}, tried #{max_tries} times: got #{e}; giving up")
+ end
+ end
+ num_tries += 1
+ end
+
cdb.create_id_map
Chef::Node.create_design_document
Chef::Role.create_design_document