Commit 2da5a3de authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[640] fix race condition in stats test

parent f328341c
...@@ -205,9 +205,12 @@ class TestStats(unittest.TestCase): ...@@ -205,9 +205,12 @@ class TestStats(unittest.TestCase):
# Override moduleCCSession so we can check if send_stopping is called # Override moduleCCSession so we can check if send_stopping is called
self.stats.mccs = MockModuleCCSession() self.stats.mccs = MockModuleCCSession()
self.assertEqual(send_shutdown("Stats"), (0, None)) self.assertEqual(send_shutdown("Stats"), (0, None))
self.assertTrue(self.stats.mccs.stopped)
self.assertFalse(self.stats.running) self.assertFalse(self.stats.running)
self.stats_server.shutdown() # Call server.shutdown with argument True so the thread.join() call
# blocks and we are sure the main loop has finished (and set
# mccs.stopped)
self.stats_server.shutdown(True)
self.assertTrue(self.stats.mccs.stopped)
# start with err # start with err
self.stats = stats.Stats() self.stats = stats.Stats()
......
...@@ -72,9 +72,19 @@ class ThreadingServerManager: ...@@ -72,9 +72,19 @@ class ThreadingServerManager:
self.server._started.wait() self.server._started.wait()
self.server._started.clear() self.server._started.clear()
def shutdown(self): def shutdown(self, blocking=False):
"""Shut down the server by calling its own shutdown() method.
Then wait for its thread to finish. If blocking is True,
the thread.join() blocks until the thread finishes. If not,
it uses a zero timeout. The latter is necessary in a number
of existing tests. We should redo this part (we should not
even need threads in most, if not all, of these threads, see
ticket #1668)"""
self.server.shutdown() self.server.shutdown()
self.server._thread.join(0) # timeout is 0 if blocking:
self.server._thread.join()
else:
self.server._thread.join(0) # timeout is 0
def do_nothing(*args, **kwargs): pass def do_nothing(*args, **kwargs): pass
......
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