Skip to content

Commit

Permalink
[FIX] test: HttpCase wait http requests to finish
Browse files Browse the repository at this point in the history
bzr revid: chs@openerp.com-20140410123519-wngil3aghdc6llqc
  • Loading branch information
KangOl committed Apr 10, 2014
1 parent bd8fc24 commit 95701c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions openerp/service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def server_activate(self):
# 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.
Expand All @@ -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()):
Expand Down
10 changes: 10 additions & 0 deletions openerp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,18 @@ def phantom_run(self, cmd, timeout):
# 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,
Expand Down

0 comments on commit 95701c2

Please sign in to comment.