From d3e550df826014365ab3cd7c174724e8dc22b425 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 3 Nov 2023 10:12:46 +0100 Subject: [PATCH 1/2] setting a timeout for the start of the test server --- cdci_data_analysis/pytest_fixtures.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cdci_data_analysis/pytest_fixtures.py b/cdci_data_analysis/pytest_fixtures.py index bcf234318..86d11f126 100644 --- a/cdci_data_analysis/pytest_fixtures.py +++ b/cdci_data_analysis/pytest_fixtures.py @@ -655,6 +655,8 @@ def dispatcher_test_conf(dispatcher_test_conf_fn): def start_dispatcher(rootdir, test_conf_fn, multithread=False, gunicorn=False): clean_test_dispatchers() + timeout_sec_thread_start = 90 + env = copy.deepcopy(dict(os.environ)) print(("rootdir", str(rootdir))) env['PYTHONPATH'] = str(rootdir) + ":" + str(rootdir) + "/tests:" + \ @@ -742,13 +744,18 @@ def follow_output(): print(f"{C}following server: server ready, url {url_store[0]}") - thread = Thread(target=follow_output, args=()) - thread.start() + start_thread(target=follow_output) started_waiting = time.time() while url_store[0] is None: - print("waiting for server to start since", time.time() - started_waiting) - time.sleep(0.2) + waiting_time_for_start = time.time() - started_waiting + print(f"waiting for server to start since {waiting_time_for_start}") + if waiting_time_for_start > timeout_sec_thread_start: + kill_child_processes(p.pid, signal.SIGINT) + os.kill(p.pid, signal.SIGINT) + start_thread(target=follow_output) + else: + time.sleep(0.2) time.sleep(0.5) service = url_store[0] @@ -758,6 +765,9 @@ def follow_output(): pid=p.pid ) +def start_thread(target): + thread = Thread(target=target, args=()) + thread.start() @pytest.fixture def gunicorn_dispatcher_long_living_fixture(gunicorn_tmp_path, gunicorn_dispatcher, dispatcher_long_living_fixture): From 1ed43f3056268fb227e78e0416b461556bc60146 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 3 Nov 2023 10:33:38 +0100 Subject: [PATCH 2/2] some logging --- cdci_data_analysis/pytest_fixtures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cdci_data_analysis/pytest_fixtures.py b/cdci_data_analysis/pytest_fixtures.py index 86d11f126..63cbd7c8e 100644 --- a/cdci_data_analysis/pytest_fixtures.py +++ b/cdci_data_analysis/pytest_fixtures.py @@ -751,6 +751,7 @@ def follow_output(): waiting_time_for_start = time.time() - started_waiting print(f"waiting for server to start since {waiting_time_for_start}") if waiting_time_for_start > timeout_sec_thread_start: + print(f"timeout for starting the server reached, re-starting the thread") kill_child_processes(p.pid, signal.SIGINT) os.kill(p.pid, signal.SIGINT) start_thread(target=follow_output)