From f3e2581b73874aef431f712935883a607a580fa5 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 19 Aug 2024 15:31:36 +0100 Subject: [PATCH] Rewrite test_service.py without need of extra argument --- softpack_core/service.py | 3 --- tests/unit/test_service.py | 14 +++++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/softpack_core/service.py b/softpack_core/service.py index caecf60..31ec4e9 100644 --- a/softpack_core/service.py +++ b/softpack_core/service.py @@ -6,7 +6,6 @@ import urllib.parse -from multiprocessing import Event from multiprocessing.synchronize import Event as EventClass from pathlib import Path @@ -53,7 +52,6 @@ def run( help="Create and use this branch of Artefacts repo.", ), ] = 'main', - serviceReady: EventClass = Event(), ) -> None: """Start the SoftPack Core REST API service. @@ -71,7 +69,6 @@ def run( artifacts.clone_repo(branch=branch) - serviceReady.set() uvicorn.run( "softpack_core.app:app.router", host=app.settings.server.host, diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index b6a82df..6da4dc8 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -15,12 +15,16 @@ def test_service_run() -> None: - ready = multiprocessing.Event() - run = multiprocessing.Process(target=ServiceAPI.run, kwargs={"serviceReady": ready}) + run = multiprocessing.Process(target=ServiceAPI.run) run.start() - ready.wait(timeout=300) - sleep(10) - response = httpx.get(app.url()) + while True: + try: + response = httpx.get(app.url()) + break + except httpx.RequestError: + if not run.is_alive(): + raise Exception("Service failed to start.") + sleep(5) run.terminate() status = Box(response.json()) assert status.softpack.core.version == __version__