Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avocado/utils/network.py: use random port allocation by default
AFAICT, most users of find_free_port() don't really care about the
port number being the first in the range, and to be honest, most users
I've seen don't even give a range.

So, the result when using the first port in the range is a high change
of collision, with no real benefit.  Let's change the default policy,
using a random port allocation.

PS: this is motivated by real world collisions I've experienced when
running tests in parallel, *and* when running other loads in the same
machine along tests.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
  • Loading branch information
clebergnu committed May 14, 2019
1 parent 0116fb1 commit f232e45
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions avocado/utils/network.py
Expand Up @@ -66,7 +66,7 @@ def is_port_free(port, address):
sock.close()


def find_free_port(start_port=1024, end_port=65535, address="localhost", sequent=True):
def find_free_port(start_port=1024, end_port=65535, address="localhost", sequent=False):
"""
Return a host free port in the range [start_port, end_port].
Expand All @@ -86,7 +86,7 @@ def find_free_port(start_port=1024, end_port=65535, address="localhost", sequent
return None


def find_free_ports(start_port, end_port, count, address="localhost", sequent=True):
def find_free_ports(start_port, end_port, count, address="localhost", sequent=False):
"""
Return count of host free ports in the range [start_port, end_port].
Expand Down

0 comments on commit f232e45

Please sign in to comment.