Commit 35fc8b2e authored by Vincent Pelletier's avatar Vincent Pelletier

test: Make http server's UntilEvent instance usable by tests.

Do not wait forever so test does not block.
Always clear event after it occurred.
Also, ensure itsUntilEvent behaviour is to raise so server actually stops
in _stopServer.
parent 642b59c2
...@@ -201,7 +201,8 @@ class UntilEvent(object): ...@@ -201,7 +201,8 @@ class UntilEvent(object):
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
while now < deadline: while now < deadline:
self._wait_event.set() self._wait_event.set()
assert self._event.wait() assert self._event.wait(10)
self._event.clear()
if self._action is ON_EVENT_EXPIRE: if self._action is ON_EVENT_EXPIRE:
now = deadline now = deadline
else: else:
...@@ -294,7 +295,7 @@ class CaucaseTest(unittest.TestCase): ...@@ -294,7 +295,7 @@ class CaucaseTest(unittest.TestCase):
""" """
Start caucased server Start caucased server
""" """
self._server_event.clear() self._server_until = until = UntilEvent(self._server_event)
self._server = server = threading.Thread( self._server = server = threading.Thread(
target=http.main, target=http.main,
kwargs={ kwargs={
...@@ -305,7 +306,7 @@ class CaucaseTest(unittest.TestCase): ...@@ -305,7 +306,7 @@ class CaucaseTest(unittest.TestCase):
#'--threshold', '31', #'--threshold', '31',
#'--key-len', '2048', #'--key-len', '2048',
) + argv, ) + argv,
'until': UntilEvent(self._server_event), 'until': until,
} }
) )
server.daemon = True server.daemon = True
...@@ -327,6 +328,7 @@ class CaucaseTest(unittest.TestCase): ...@@ -327,6 +328,7 @@ class CaucaseTest(unittest.TestCase):
Stop a running caucased server Stop a running caucased server
""" """
server = self._server server = self._server
self._server_until.action = ON_EVENT_RAISE
self._server_event.set() self._server_event.set()
server.join(2) server.join(2)
if server.is_alive(): # pragma: no cover if server.is_alive(): # pragma: no cover
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment