run-tests: prevent race-condition when picking a channel stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 24 May 2022 10:34:42 +0200
branchstable
changeset 49215 8d31ef3017c9
parent 49214 eca367970253
child 49216 9ea9445c3223
run-tests: prevent race-condition when picking a channel Before this, multiple jobs could search the list at the same time and pick the same free channel. We now project this search/assignment with a simple lock.
tests/run-tests.py
--- a/tests/run-tests.py	Tue May 24 09:57:53 2022 +0200
+++ b/tests/run-tests.py	Tue May 24 10:34:42 2022 +0200
@@ -2553,16 +2553,18 @@
         done = queue.Queue()
         running = 0
 
+        channels_lock = threading.Lock()
         channels = [""] * self._jobs
 
         def job(test, result):
-            for n, v in enumerate(channels):
-                if not v:
-                    channel = n
-                    break
-            else:
-                raise ValueError('Could not find output channel')
-            channels[channel] = "=" + test.name[5:].split(".")[0]
+            with channels_lock:
+                for n, v in enumerate(channels):
+                    if not v:
+                        channel = n
+                        break
+                else:
+                    raise ValueError('Could not find output channel')
+                channels[channel] = "=" + test.name[5:].split(".")[0]
 
             r = None
             try: