[FIX] test: HttpCase wait http requests to finish
bzr revid: chs@openerp.com-20140410123519-wngil3aghdc6llqc
This commit is contained in:
parent
bd8fc24dc1
commit
95701c28c0
|
@ -62,6 +62,14 @@ class BaseWSGIServerNoBind(werkzeug.serving.BaseWSGIServer):
|
|||
# dont listen as we use PreforkServer#socket
|
||||
pass
|
||||
|
||||
|
||||
class RequestHandler(werkzeug.serving.WSGIRequestHandler):
|
||||
def setup(self):
|
||||
# flag the current thread as handling a http request
|
||||
super(RequestHandler, self).setup()
|
||||
me = threading.currentThread()
|
||||
me.name = 'openerp.service.http.request.%s' % (me.ident,)
|
||||
|
||||
# _reexec() should set LISTEN_* to avoid connection refused during reload time. It
|
||||
# should also work with systemd socket activation. This is currently untested
|
||||
# and not yet used.
|
||||
|
@ -71,6 +79,10 @@ class ThreadedWSGIServerReloadable(werkzeug.serving.ThreadedWSGIServer):
|
|||
given by the environement, this is used by autoreload to keep the listen
|
||||
socket open when a reload happens.
|
||||
"""
|
||||
def __init__(self, host, port, app):
|
||||
super(ThreadedWSGIServerReloadable, self).__init__(host, port, app,
|
||||
handler=RequestHandler)
|
||||
|
||||
def server_bind(self):
|
||||
envfd = os.environ.get('LISTEN_FDS')
|
||||
if envfd and os.environ.get('LISTEN_PID') == str(os.getpid()):
|
||||
|
|
|
@ -229,8 +229,18 @@ class HttpCase(TransactionCase):
|
|||
# kill phantomjs if phantom.exit() wasn't called in the test
|
||||
if phantom.poll() is None:
|
||||
phantom.terminate()
|
||||
self._wait_remaining_requests()
|
||||
_logger.info("phantom_run execution finished")
|
||||
|
||||
def _wait_remaining_requests(self):
|
||||
for thread in threading.enumerate():
|
||||
if thread.name.startswith('openerp.service.http.request.'):
|
||||
while thread.isAlive():
|
||||
# Need a busyloop here as thread.join() masks signals
|
||||
# and would prevent the forced shutdown.
|
||||
thread.join(0.05)
|
||||
time.sleep(0.05)
|
||||
|
||||
def phantom_jsfile(self, jsfile, timeout=60, **kw):
|
||||
options = {
|
||||
'timeout' : timeout,
|
||||
|
|
Loading…
Reference in New Issue