Skip to content

Commit

Permalink
Merge pull request #6048 from drew2a/fix/6042
Browse files Browse the repository at this point in the history
Fix test_get_first_free_port
  • Loading branch information
drew2a authored Apr 6, 2021
2 parents 78204b1 + de1c34c commit 07fe24a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tribler-core/tribler_core/tests/test_network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def test_autodetect_socket_style():

def test_get_first_free_port():
# target port is free
assert get_first_free_port(start=50000) == 50000
port = random.randint(50000, 60000)
assert get_first_free_port(start=port) == port

# target port is locked
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind(('', 50000))
assert get_first_free_port(start=50000) == 50001
sock.bind(('', port))
assert get_first_free_port(start=port) == port + 1

# no free ports found
with pytest.raises(FreePortNotFoundError):
get_first_free_port(start=50000, limit=0)
get_first_free_port(start=port, limit=0)

0 comments on commit 07fe24a

Please sign in to comment.