]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
tests/functional: Use more fine-grained locking when looking for free ports
authorThomas Huth <thuth@redhat.com>
Thu, 21 Aug 2025 09:47:35 +0000 (11:47 +0200)
committerThomas Huth <thuth@redhat.com>
Wed, 27 Aug 2025 07:46:54 +0000 (09:46 +0200)
Currently, we have one lock that is held while a test is looking for
free ports. However, we are also using different ranges for looking
for free ports nowadays (PORTS_START is based on the PID of the process),
so instead of using only one lock, we should rather use a lock per
range instead. This should help to allow running more tests in parallel.

While we're at it, also create the lock files without executable bit
(mode is 0o777 by default).

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250821094735.804210-1-thuth@redhat.com>

tests/functional/qemu_test/ports.py

index 631b77abf6bc29b7fdacfda1b818e360e7b81ed5..81174a6153280f815850064d30d5870b2e85e6cb 100644 (file)
@@ -23,8 +23,9 @@ class Ports():
     PORTS_END = PORTS_START + PORTS_RANGE_SIZE
 
     def __enter__(self):
-        lock_file = os.path.join(BUILD_DIR, "tests", "functional", "port_lock")
-        self.lock_fh = os.open(lock_file, os.O_CREAT)
+        lock_file = os.path.join(BUILD_DIR, "tests", "functional",
+                                 f".port_lock.{self.PORTS_START}")
+        self.lock_fh = os.open(lock_file, os.O_CREAT, mode=0o666)
         fcntl.flock(self.lock_fh, fcntl.LOCK_EX)
         return self