Skip to content

Commit

Permalink
test: Update testing settings to use unique port numbers for each par…
Browse files Browse the repository at this point in the history
…allel test environment to avoid collisions when running via tox
  • Loading branch information
nfelt14 committed Oct 1, 2024
1 parent 97a7cbd commit f6cc089
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ task-tags = ["FIXME", "FUTURE", "RELIC", "TODO"]
[tool.ruff.lint.isort]
force-sort-within-sections = false
known-first-party = [
"conftest",
"tekhsi"
]
known-local-folder = [
"server",
"tests"
]
lines-between-types = 1
order-by-type = false

Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from tekhsi._tek_highspeed_server_pb2_grpc import ConnectStub
from tekhsi.tek_hsi_connect import TekHSIConnect

from server.tekhsi_test_server import TEST_SERVER_ADDRESS, TEST_SERVER_PORT_NUMBER

PROJECT_ROOT_DIR = Path(__file__).parent.parent


Expand All @@ -36,7 +38,7 @@ def data_arrival(waveforms: List[DerivedWaveform]):


class TestServerManager:
def __init__(self, port=5000):
def __init__(self, port=TEST_SERVER_PORT_NUMBER):
"""Initialize the TestServerManager with a specified port."""
self.server_process = None
self.port = port
Expand Down Expand Up @@ -126,7 +128,7 @@ def expected_header():
@pytest.fixture()
def grpc_channel(): # pylint: disable=useless-suppression
"""Create a gRPC channel to the test server."""
channel = grpc.insecure_channel("localhost:5000")
channel = grpc.insecure_channel(TEST_SERVER_ADDRESS)
yield channel
channel.close()

Expand All @@ -147,4 +149,4 @@ def start_test_server():
@pytest.fixture()
def tekhsi_client():
"""Create a TekHSIConnect client."""
return TekHSIConnect("localhost:5000")
return TekHSIConnect(TEST_SERVER_ADDRESS)
5 changes: 4 additions & 1 deletion tests/server/tekhsi_test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
server = None
acq_id = 0

TEST_SERVER_PORT_NUMBER = int(f"5{sys.version_info.major}{sys.version_info.minor}")
TEST_SERVER_ADDRESS = f"localhost:{TEST_SERVER_PORT_NUMBER}"


class WfmDataType(Enum):
Int8 = 1
Expand Down Expand Up @@ -737,7 +740,7 @@ def serve():
try:
if verbose:
print("Server Startup Request")
server.add_insecure_port("[::]:5000")
server.add_insecure_port(f"[::]:{TEST_SERVER_PORT_NUMBER}")
server.start()
time.sleep(2)
if verbose:
Expand Down

0 comments on commit f6cc089

Please sign in to comment.