summaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-05-26 15:11:43 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-05-26 15:28:28 -0300
commitfe19e46c8f11f5b27164112a61a7405aa0e0d455 (patch)
treeb63533964de27e67f55981f1e9861a2c6f7832d9 /common/src
parent6d4953457726ec7830e48fb899e2e8c17b1ec995 (diff)
[feat] Retry to start couch and clean properly
Now the CouchDB based tests will try 3 times before give up due to timeout or some temporary error. The stop function will also execute properly even if the process wasn't created, leaving no lost files or folders behind.
Diffstat (limited to 'common/src')
-rw-r--r--common/src/leap/soledad/common/tests/util.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py
index 567bc314..17ed3855 100644
--- a/common/src/leap/soledad/common/tests/util.py
+++ b/common/src/leap/soledad/common/tests/util.py
@@ -30,6 +30,7 @@ import u1db
import subprocess
import time
import re
+import traceback
from mock import Mock
from urlparse import urljoin
@@ -316,8 +317,21 @@ class CouchDBWrapper(object):
testing.
"""
BOOT_TIMEOUT_SECONDS = 5
+ RETRY_LIMIT = 3
def start(self):
+ tries = 0
+ while tries < self.RETRY_LIMIT and not hasattr(self, 'port'):
+ try:
+ self._try_start()
+ return
+ except Exception, e:
+ print traceback.format_exc()
+ self.stop()
+ tries += 1
+ raise Exception("Check your couchdb: Tried to start 3 times and failed badly")
+
+ def _try_start(self):
"""
Start a CouchDB instance for a test.
"""
@@ -391,8 +405,13 @@ stderr:
"""
Terminate the CouchDB instance.
"""
- self.process.terminate()
- self.process.communicate()
+ try:
+ self.process.terminate()
+ self.process.communicate()
+ except:
+ # just to clean up
+ # if it can't, the process wasn't created anyway
+ pass
shutil.rmtree(self.tempdir)