Skip to content

Commit fe8ede1

Browse files
committed
feat: dynamically assign port and catalog URL in test setup
1 parent 553a767 commit fe8ede1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

rerun_py/tests/unit/test_datafusion_tables.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import pathlib
55
import platform
6+
import socket
67
import subprocess
78
import time
89
from typing import TYPE_CHECKING
@@ -20,8 +21,8 @@
2021
from rerun_bindings import DatasetEntry
2122

2223
HOST = "localhost"
23-
PORT = 51234
24-
CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
24+
PORT = None # Will be set dynamically
25+
CATALOG_URL = None # Will be set dynamically
2526
DATASET_NAME = "dataset"
2627

2728
DATASET_FILEPATH = pathlib.Path(__file__).parent.parent.parent.parent / "tests" / "assets" / "rrd" / "dataset"
@@ -85,8 +86,6 @@ def shutdown_process(process: subprocess.Popen[str]) -> None:
8586

8687

8788
def wait_for_server_ready(timeout: int = 30) -> None:
88-
import socket
89-
9089
def is_port_open() -> bool:
9190
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9291
sock.settimeout(1)
@@ -123,7 +122,16 @@ def server_instance() -> Generator[ServerInstance, None, None]:
123122
# Server can be noisy by default
124123
env["RUST_LOG"] = "warning"
125124

126-
# TODO(#11173): pick a free port
125+
# Find a free port dynamically
126+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
127+
sock.bind((HOST, 0))
128+
global PORT
129+
PORT = sock.getsockname()[1]
130+
sock.close()
131+
132+
global CATALOG_URL
133+
CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
134+
127135
cmd = ["python", "-m", "rerun", "server", "--dataset", str(DATASET_FILEPATH), "--table", str(TABLE_FILEPATH)]
128136
server_process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
129137

0 commit comments

Comments
 (0)