|
3 | 3 | import os
|
4 | 4 | import pathlib
|
5 | 5 | import platform
|
| 6 | +import socket |
6 | 7 | import subprocess
|
7 | 8 | import time
|
8 | 9 | from typing import TYPE_CHECKING
|
|
20 | 21 | from rerun_bindings import DatasetEntry
|
21 | 22 |
|
22 | 23 | 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}" |
25 | 27 | DATASET_NAME = "dataset"
|
26 | 28 |
|
27 | 29 | 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:
|
85 | 87 |
|
86 | 88 |
|
87 | 89 | def wait_for_server_ready(timeout: int = 30) -> None:
|
88 |
| - import socket |
89 |
| - |
90 | 90 | def is_port_open() -> bool:
|
91 | 91 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
92 | 92 | sock.settimeout(1)
|
@@ -123,7 +123,16 @@ def server_instance() -> Generator[ServerInstance, None, None]:
|
123 | 123 | # Server can be noisy by default
|
124 | 124 | env["RUST_LOG"] = "warning"
|
125 | 125 |
|
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 | + |
127 | 136 | cmd = ["python", "-m", "rerun", "server", "--dataset", str(DATASET_FILEPATH), "--table", str(TABLE_FILEPATH)]
|
128 | 137 | server_process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
129 | 138 |
|
|
0 commit comments