From 90bec3f372b188a37adccef2f2e2dd17df1a8e48 Mon Sep 17 00:00:00 2001 From: Kefei Mo Date: Thu, 31 Oct 2024 11:13:00 -0500 Subject: [PATCH] added random to get_free_port --- tests/test_dnp3_python/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_dnp3_python/utils.py b/tests/test_dnp3_python/utils.py index 65cd450..1f25cad 100644 --- a/tests/test_dnp3_python/utils.py +++ b/tests/test_dnp3_python/utils.py @@ -1,3 +1,4 @@ +import random import socket from time import sleep @@ -31,7 +32,9 @@ def get_free_port(host="127.0.0.1", start_port=20000, end_port=30000): port = get_free_port() print(f"Port {port} is available.") """ - for port in range(start_port, end_port + 1): + ports = list(range(start_port, end_port + 1)) + random.shuffle(ports) + for port in ports: if not check_port_in_use(port, host): return port sleep(1)