This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new eb6a74d56 mango: revisit test database recreation logic
eb6a74d56 is described below
commit eb6a74d5603d4bac1d77fc895946ffbdd99f4b97
Author: Gabor Pali <[email protected]>
AuthorDate: Sun Jun 4 00:59:51 2023 +0200
mango: revisit test database recreation logic
Databases used for integration testing are being recreated by
unbounded recursion which can blow up the stack in case of
unrecoverable errors.
Replace the tail recursion for a regular loop, set an upper limit
for the number of tries, and signal the problem with a more
descriptive message. Introduce an increasing delay between the
subsequent tries for tolerance against transient errors.
---
src/mango/test/mango.py | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index 20a40d1b7..ad9747a92 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -77,16 +77,22 @@ class Database(object):
r = self.sess.delete(self.url)
def recreate(self):
- r = self.sess.get(self.url)
- if r.status_code == 200:
- db_info = r.json()
- docs = db_info["doc_count"] + db_info["doc_del_count"]
- if docs == 0:
- # db never used - create unnecessary
- return
- self.delete()
- self.create()
- self.recreate()
+ NUM_TRIES = 10
+
+ for k in range(NUM_TRIES):
+ r = self.sess.get(self.url)
+ if r.status_code == 200:
+ db_info = r.json()
+ docs = db_info["doc_count"] + db_info["doc_del_count"]
+ if docs == 0:
+ # db exists and it is empty -- exit condition is met
+ return
+ self.delete()
+ self.create()
+ time.sleep(k * 0.1)
+ raise Exception(
+ "Failed to recreate the database after {} tries".format(NUM_TRIES)
+ )
def save_doc(self, doc):
self.save_docs([doc])