Do not limit event assert to first event

This commit is contained in:
Daniel A. Wozniak 2019-04-14 05:14:46 +00:00 committed by Pedro Algarvio
parent 304229240e
commit 6c8c4182dd
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -706,20 +706,18 @@ class SaltMinionEventAssertsMixin(object):
raise salt.exceptions.NotImplemented('assertMinionEventFired() not implemented')
def assertMinionEventReceived(self, desired_event, timeout=5, sleep_time=0.5):
queue_wait = timeout / sleep_time
while self.q.empty():
time.sleep(sleep_time) # Wait for events to be pushed into the queue
queue_wait -= 1
if queue_wait <= 0:
raise AssertionError('Queue wait timer expired')
while not self.q.empty(): # This is not thread-safe and may be inaccurate
event = self.q.get()
start = time.time()
while True:
try:
event = self.q.get(False)
except Emtpy:
time.sleep(sleep_time)
if isinstance(event, dict):
event.pop('_stamp')
if desired_event == event:
self.fetch_proc.terminate()
return True
if time.time() - start >= timeout:
if start - time.time() >= timeout:
break
self.fetch_proc.terminate()
raise AssertionError('Event {0} was not received by minion'.format(desired_event))