Browse Source

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
tags/3.6.0
Tobias Henkel 2 months ago
parent
commit
f5c6e37c84
No account linked to committer's email address
1 changed files with 7 additions and 1 deletions
  1. 7
    1
      zuul/executor/server.py

+ 7
- 1
zuul/executor/server.py View File

@@ -179,9 +179,14 @@ class Watchdog(object):
179 179
         self.thread.daemon = True
180 180
         self.timed_out = None
181 181
 
182
+        self.end = 0
183
+
184
+        self._running = False
185
+        self._stop_event = threading.Event()
186
+
182 187
     def _run(self):
183 188
         while self._running and time.time() < self.end:
184
-            time.sleep(10)
189
+            self._stop_event.wait(10)
185 190
         if self._running:
186 191
             self.timed_out = True
187 192
             self.function(*self.args)
@@ -198,6 +203,7 @@ class Watchdog(object):
198 203
 
199 204
     def stop(self):
200 205
         self._running = False
206
+        self._stop_event.set()
201 207
 
202 208
 
203 209
 class SshAgent(object):

Loading…
Cancel
Save