Skip to content

Commit e8de496

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

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

rerun_py/tests/unit/test_datafusion_tables.py

Lines changed: 14 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,9 @@
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
26+
# CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
2527
DATASET_NAME = "dataset"
2628

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

8688

8789
def wait_for_server_ready(timeout: int = 30) -> None:
88-
import socket
89-
9090
def is_port_open() -> bool:
9191
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9292
sock.settimeout(1)
@@ -123,7 +123,16 @@ def server_instance() -> Generator[ServerInstance, None, None]:
123123
# Server can be noisy by default
124124
env["RUST_LOG"] = "warning"
125125

126-
# TODO(#11173): pick a free port
126+
# Find a free port dynamically
127+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
128+
s.bind((HOST, 0))
129+
free_port = s.getsockname()[1]
130+
131+
# Set the global variables for the session
132+
global PORT, CATALOG_URL
133+
PORT = free_port
134+
CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
135+
127136
cmd = ["python", "-m", "rerun", "server", "--dataset", str(DATASET_FILEPATH), "--table", str(TABLE_FILEPATH)]
128137
server_process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
129138

0 commit comments

Comments
 (0)