Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions rerun_py/tests/unit/test_datafusion_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pathlib
import platform
import socket
import subprocess
import time
from typing import TYPE_CHECKING
Expand All @@ -20,8 +21,6 @@
from rerun_bindings import DatasetEntry

HOST = "localhost"
PORT = 51234
CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
DATASET_NAME = "dataset"

DATASET_FILEPATH = pathlib.Path(__file__).parent.parent.parent.parent / "tests" / "assets" / "rrd" / "dataset"
Expand Down Expand Up @@ -84,14 +83,12 @@ def shutdown_process(process: subprocess.Popen[str]) -> None:
print(f"Error during cleanup: {e}")


def wait_for_server_ready(timeout: int = 30) -> None:
import socket

def wait_for_server_ready(port: int, timeout: int = 30) -> None:
def is_port_open() -> bool:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
try:
result = sock.connect_ex((HOST, PORT))
result = sock.connect_ex((HOST, port))
return result == 0
finally:
sock.close()
Expand All @@ -103,7 +100,7 @@ def is_port_open() -> bool:
break
time.sleep(0.1)
else:
raise TimeoutError(f"Server port {PORT} not ready within {timeout}s")
raise TimeoutError(f"Server port {port} not ready within {timeout}s")


class ServerInstance:
Expand All @@ -123,7 +120,14 @@ def server_instance() -> Generator[ServerInstance, None, None]:
# Server can be noisy by default
env["RUST_LOG"] = "warning"

# TODO(#11173): pick a free port
# Find a free port dynamically
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((HOST, 0))
port = sock.getsockname()[1]
sock.close()

catalog_url = f"rerun+http://{HOST}:{port}"

cmd = [
"python",
"-m",
Expand All @@ -141,11 +145,11 @@ def server_instance() -> Generator[ServerInstance, None, None]:
server_process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

try:
wait_for_server_ready()
wait_for_server_ready(port)
except Exception as e:
print(f"Error during waiting for server to start: {e}")

client = CatalogClient(CATALOG_URL)
client = CatalogClient(catalog_url)
dataset = client.get_dataset(name=DATASET_NAME)

resource = ServerInstance(server_process, client, dataset)
Expand Down
Loading