commit c9cc0f558cfe086d8e72e4fd9bf31c98ad535041 Author: Damian Johnson atagar@torproject.org Date: Sun Aug 12 14:08:09 2018 -0700
Wait for unit tests to consume events
On #27053 Dave's reported that even with a bumped sleep these new tests occasionally fail for him. Sleeps within tests are a code stink so I really should do something smarter anyway.
Waiting up to five seconds for unit tests to consume the events they emit. When we run both our unit and integ tests the later performs heavy tests asychrously. This tends to peg the CPU while running our unit tests, probably slowing things down enough for them to fail occasionly for Dave. --- test/unit/control/controller.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py index 8034abe2..eba612fd 100644 --- a/test/unit/control/controller.py +++ b/test/unit/control/controller.py @@ -826,7 +826,14 @@ class TestControl(unittest.TestCase): self.controller._event_queue.put(uncast_event) self.controller._event_notice.set()
- # doesn't seem necessary in practice, but since event processing is - # asynchronous giving it a tiny bit of time to get handled + # Wait for the event to get asynchronously consumed. This should happen + # right away, but if the system is bogged down it may take quite a few + # milliseconds.
- time.sleep(0.03) + event_sent_at = time.time() + + while not self.controller._event_queue.empty(): + time.sleep(0.01) + + if time.time() - event_sent_at > 5: + self.fail('Event did not get processed after five seconds')