On Thu, Aug 21, 2025 at 12:49 PM Thomas Huth <[email protected]> wrote:
>
> From: Thomas Huth <[email protected]>
>
> 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).
>

(Unrelated to this patch but the file itself)

Hm. AF_INET supports binding to port 0 to connect to any available
port (see man 7 ip). Is this not portable?

> Signed-off-by: Thomas Huth <[email protected]>
> ---
>  tests/functional/qemu_test/ports.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tests/functional/qemu_test/ports.py 
> b/tests/functional/qemu_test/ports.py
> index 631b77abf6b..81174a61532 100644
> --- a/tests/functional/qemu_test/ports.py
> +++ b/tests/functional/qemu_test/ports.py
> @@ -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
>
> --
> 2.50.1
>
>

Reply via email to