Skip to content

Commit

Permalink
Improve error if port is not available for XRootD (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicholas Smith <[email protected]>
  • Loading branch information
chrisburr and nsmith- authored Mar 5, 2024
1 parent 72c5b28 commit 4930488
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/test_basicio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import shutil
import socket
import subprocess
import time

Expand All @@ -16,19 +17,29 @@
_vectors_to_chunks,
)

XROOTD_PORT = 1094
TESTDATA1 = "apple\nbanana\norange\ngrape"
TESTDATA2 = "red\ngreen\nyellow\nblue"
sleep_time = 0.2
expiry_time = 0.1


def require_port_availability(port: int) -> bool:
"""Raise an exception if the given port is already in use."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("localhost", port)) == 0:
raise RuntimeError(f"This test requires port {port} to be available")


@pytest.fixture(scope="module")
def localserver(tmpdir_factory):
require_port_availability(XROOTD_PORT)

srvdir = tmpdir_factory.mktemp("srv")
tempPath = os.path.join(srvdir, "Folder")
os.mkdir(tempPath)
xrdexe = shutil.which("xrootd")
proc = subprocess.Popen([xrdexe, srvdir])
proc = subprocess.Popen([xrdexe, "-p", str(XROOTD_PORT), srvdir])
time.sleep(2) # give it some startup
yield "root://localhost/" + str(tempPath), tempPath
proc.terminate()
Expand Down

0 comments on commit 4930488

Please sign in to comment.