From 97cd46960c7dacdda3739223fee129c672fef82e Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 22 May 2015 19:03:05 -0300 Subject: [bug] Avoid infinite loop starting couch for tests As described in #4691, sometimes couch just hangs and all testing freezes. This is due to no output from couch (sometimes meaning that an error on boot wasn't logged). This adds a timeout and checks for it while booting for tests. Closes #4691 --- common/src/leap/soledad/common/tests/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'common/src/leap/soledad') diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py index 75379fdc..567bc314 100644 --- a/common/src/leap/soledad/common/tests/util.py +++ b/common/src/leap/soledad/common/tests/util.py @@ -315,6 +315,7 @@ class CouchDBWrapper(object): Wrapper for external CouchDB instance which is started and stopped for testing. """ + BOOT_TIMEOUT_SECONDS = 5 def start(self): """ @@ -347,6 +348,7 @@ class CouchDBWrapper(object): self.process = subprocess.Popen( args, env=None, stdout=null.fileno(), stderr=null.fileno(), close_fds=True) + boot_time = time.time() # find port logPath = os.path.join(self.tempdir, 'log', 'couch.log') while not os.path.exists(logPath): @@ -365,8 +367,14 @@ stderr: %s""" % ( self.process.returncode, got_stdout, got_stderr)) time.sleep(0.01) + if (time.time() - boot_time) > self.BOOT_TIMEOUT_SECONDS: + self.stop() + raise Exception("Timeout starting couch") while os.stat(logPath).st_size == 0: time.sleep(0.01) + if (time.time() - boot_time) > self.BOOT_TIMEOUT_SECONDS: + self.stop() + raise Exception("Timeout starting couch") PORT_RE = re.compile( 'Apache CouchDB has started on http://127.0.0.1:(?P\d+)') -- cgit v1.2.3