From 3f237fd805ebecd917f07014bd0a701e2d0b7faf Mon Sep 17 00:00:00 2001 From: Oleksii Moskalenko Date: Mon, 16 May 2022 11:50:01 -0700 Subject: [PATCH] assert that port is free before python server starts and free by the end Signed-off-by: Oleksii Moskalenko --- sdk/python/tests/conftest.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdk/python/tests/conftest.py b/sdk/python/tests/conftest.py index d492c7ba845..092f5a07873 100644 --- a/sdk/python/tests/conftest.py +++ b/sdk/python/tests/conftest.py @@ -274,10 +274,11 @@ def pytest_generate_tests(metafunc: pytest.Metafunc): @pytest.fixture(scope="session") def python_server(environment): + assert not _check_port_open("localhost", environment.get_local_server_port()) + proc = Process( target=start_test_local_server, args=(environment.feature_store.repo_path, environment.get_local_server_port()), - daemon=True, ) if ( environment.python_feature_server @@ -298,6 +299,15 @@ def python_server(environment): if proc.is_alive(): proc.kill() + # wait server to free the port + wait_retry_backoff( + lambda: ( + None, + not _check_port_open("localhost", environment.get_local_server_port()), + ), + timeout_secs=30, + ) + def _check_port_open(host, port) -> bool: with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: