summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Monniez <moc@odoo.com>2019-08-16 09:43:45 +0000
committerChristophe Monniez <moc@odoo.com>2019-08-21 14:13:58 +0000
commit3ca788f558bbdd68eaec7f57266bfbd17c2370e5 (patch)
tree844a10cacd11257b40771228e9a76c595a6003ad
parentf5f940a29186a4be4342b9cb3baaee55e5b1d6ff (diff)
[IMP] tests: refactor _wait_remaining_requests
After a browser_js, http requests threads are joined. If one of them doesn't finish gracefully, a dumpstacks occurs. As the dumpstacks call is in a loop, it can quickly polute logs. Even more, a the dumptack may include threads that were not yet processed and that will be joined in a future loop. With this commit, dumpstacks will be called once and for all at the end of the method, if at least one thread is remaining. Furthermore, before this commit a sleep of 0.5 sec occured at most ten times for each thread before considering it as lost. It means that each thread is benefiting of the cumumulated time of the previous ones. That's not fair. With this commit, a default timeout of 10 sec is used for all threads. The original warning is kept for each remaining request.
-rw-r--r--odoo/tests/common.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/odoo/tests/common.py b/odoo/tests/common.py
index 6485092c6bb..3611fec68b2 100644
--- a/odoo/tests/common.py
+++ b/odoo/tests/common.py
@@ -929,26 +929,26 @@ class HttpCase(TransactionCase):
return self.opener.post(url, data=data, files=files, timeout=timeout, headers=headers)
return self.opener.get(url, timeout=timeout, headers=headers)
- def _wait_remaining_requests(self):
- t0 = int(time.time())
- for thread in threading.enumerate():
- if thread.name.startswith('odoo.service.http.request.'):
- join_retry_count = 10
- while thread.isAlive():
- # Need a busyloop here as thread.join() masks signals
- # and would prevent the forced shutdown.
- thread.join(0.05)
- join_retry_count -= 1
- if join_retry_count < 0:
- self._logger.warning("Stop waiting for thread %s handling request for url %s",
- thread.name, getattr(thread, 'url', '<UNKNOWN>'))
- break
- time.sleep(0.5)
- t1 = int(time.time())
- if t0 != t1:
- self._logger.info('remaining requests')
- odoo.tools.misc.dumpstacks()
- t0 = t1
+ def _wait_remaining_requests(self, timeout=10):
+
+ def get_http_request_threads():
+ return [t for t in threading.enumerate() if t.name.startswith('odoo.service.http.request.')]
+
+ start_time = time.time()
+ request_threads = get_http_request_threads()
+ self._logger.info('waiting for threads: %s', request_threads)
+
+ for thread in request_threads:
+ thread.join(timeout - (time.time() - start_time))
+
+ request_threads = get_http_request_threads()
+ for thread in request_threads:
+ self._logger.warning("Stop waiting for thread %s handling request for url %s",
+ thread.name, getattr(thread, 'url', '<UNKNOWN>'))
+
+ if request_threads:
+ self._logger.info('remaining requests')
+ odoo.tools.misc.dumpstacks()
def authenticate(self, user, password):
# stay non-authenticated