Skip to content
This repository
Browse code

Fix timeout in await state event

When state events that you are not expecting occur, await_state_event
can never time out
  • Loading branch information...
commit 0bcddf3675c4c8c0e4fffa94965c2e31901da1cd 1 parent fc4178e
Patrick Armstrong authored

Showing 1 changed file with 5 additions and 0 deletions. Show diff stats Hide diff stats

  1. 5  ion/services/cei/test/__init__.py
5  ion/services/cei/test/__init__.py
... ...
@@ -1,4 +1,5 @@
1 1
 from gevent import queue
  2
+from datetime import datetime, timedelta
2 3
 
3 4
 from pyon.event.event import EventSubscriber
4 5
 from pyon.public import log
@@ -31,10 +32,14 @@ def await_state_event(self, pid=None, state=None, timeout=30, strict=False):
31 32
         if strict is False, allow intermediary events
32 33
         """
33 34
 
  35
+        start_time = datetime.now()
  36
+
34 37
         assert state in ProcessStateEnum._str_map, "process state %s unknown!" % state
35 38
         state_str = ProcessStateEnum._str_map.get(state)
36 39
 
37 40
         while 1:
  41
+            if datetime.now() - start_time > timedelta(seconds=timeout):
  42
+                raise AssertionError("Waiter timeout! Waited %s seconds for process %s state %s" % (timeout, pid, state_str))
38 43
             try:
39 44
                 event = self.event_queue.get(timeout=timeout)
40 45
             except queue.Empty:

0 notes on commit 0bcddf3

Please sign in to comment.
Something went wrong with that request. Please try again.