Skip to content

Commit

Permalink
added random to get_free_port
Browse files Browse the repository at this point in the history
  • Loading branch information
kefeimo committed Oct 31, 2024
1 parent 1ee1987 commit 90bec3f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/test_dnp3_python/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
import socket
from time import sleep

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 90bec3f

Please sign in to comment.