Skip to content

Commit 13f7b40

Browse files
committed
fix: Avoid global
1 parent 351817f commit 13f7b40

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

rerun_py/tests/unit/test_datafusion_tables.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
from rerun_bindings import DatasetEntry
2222

2323
HOST = "localhost"
24-
PORT = None # Will be set dynamically
25-
CATALOG_URL = None # Will be set dynamically
2624
DATASET_NAME = "dataset"
2725

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

8785

88-
def wait_for_server_ready(timeout: int = 30) -> None:
86+
def wait_for_server_ready(port: int, timeout: int = 30) -> None:
8987
def is_port_open() -> bool:
9088
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9189
sock.settimeout(1)
9290
try:
93-
result = sock.connect_ex((HOST, PORT))
91+
result = sock.connect_ex((HOST, port))
9492
return result == 0
9593
finally:
9694
sock.close()
@@ -102,7 +100,7 @@ def is_port_open() -> bool:
102100
break
103101
time.sleep(0.1)
104102
else:
105-
raise TimeoutError(f"Server port {PORT} not ready within {timeout}s")
103+
raise TimeoutError(f"Server port {port} not ready within {timeout}s")
106104

107105

108106
class ServerInstance:
@@ -125,22 +123,20 @@ def server_instance() -> Generator[ServerInstance, None, None]:
125123
# Find a free port dynamically
126124
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
127125
sock.bind((HOST, 0))
128-
global PORT
129-
PORT = sock.getsockname()[1]
126+
port = sock.getsockname()[1]
130127
sock.close()
131128

132-
global CATALOG_URL
133-
CATALOG_URL = f"rerun+http://{HOST}:{PORT}"
129+
catalog_url = f"rerun+http://{HOST}:{port}"
134130

135131
cmd = ["python", "-m", "rerun", "server", "--dataset", str(DATASET_FILEPATH), "--table", str(TABLE_FILEPATH)]
136132
server_process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
137133

138134
try:
139-
wait_for_server_ready()
135+
wait_for_server_ready(port)
140136
except Exception as e:
141137
print(f"Error during waiting for server to start: {e}")
142138

143-
client = CatalogClient(CATALOG_URL)
139+
client = CatalogClient(catalog_url)
144140
dataset = client.get_dataset(name=DATASET_NAME)
145141

146142
resource = ServerInstance(server_process, client, dataset)

0 commit comments

Comments
 (0)