Skip to content

Commit

Permalink
Ensure unique ports for multi-process tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-anoyes committed Jan 28, 2022
1 parent da424f9 commit 25caa34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/TestRunner/local_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@
import socket


def get_free_port():
def _get_free_port_internal():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('0.0.0.0', 0))
return s.getsockname()[1]


_used_ports = set()


def get_free_port():
global _used_ports
port = _get_free_port_internal()
while port in _used_ports:
port = _get_free_port_internal()
_used_ports.add(port)
return port


class LocalCluster:
configuration_template = """
## foundationdb.conf
Expand Down
4 changes: 4 additions & 0 deletions tests/TestRunner/tmp_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def close(self):
break

if errcode:
for etc_file in glob.glob(os.path.join(cluster.etc, "*")):
print(">>>>>>>>>>>>>>>>>>>> Contents of {}:".format(etc_file))
with open(etc_file, "r") as f:
print(f.read())
for log_file in glob.glob(os.path.join(cluster.log, "*")):
print(">>>>>>>>>>>>>>>>>>>> Contents of {}:".format(log_file))
with open(log_file, "r") as f:
Expand Down

0 comments on commit 25caa34

Please sign in to comment.