Fix test race with Watchdog thread still running
In some rare occasions the watchdog thread is still sleeping [1] while a test case is already finished. In this case the running thread validation fails the test. This can be solved by not sleeping for a fixed amount of time but instead wait the same time for a stop event. This makes the thread stop immediately when it is asked to stop [1] Trace File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap self._bootstrap_inner() File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/home/zuul/src/git.openstack.org/openstack-infra/zuul/zuul/executor/server.py", line 185, in _run time.sleep(10) Change-Id: I45eba5bf8f46de078fd8093719ef84e5229eafeb
This commit is contained in:
parent
967828b1f0
commit
f5c6e37c84
|
@ -179,9 +179,14 @@ class Watchdog(object):
|
|||
self.thread.daemon = True
|
||||
self.timed_out = None
|
||||
|
||||
self.end = 0
|
||||
|
||||
self._running = False
|
||||
self._stop_event = threading.Event()
|
||||
|
||||
def _run(self):
|
||||
while self._running and time.time() < self.end:
|
||||
time.sleep(10)
|
||||
self._stop_event.wait(10)
|
||||
if self._running:
|
||||
self.timed_out = True
|
||||
self.function(*self.args)
|
||||
|
@ -198,6 +203,7 @@ class Watchdog(object):
|
|||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
self._stop_event.set()
|
||||
|
||||
|
||||
class SshAgent(object):
|
||||
|
|
Loading…
Reference in New Issue