Skip to content

Commit

Permalink
Rewrite test_service.py without need of extra argument
Browse files Browse the repository at this point in the history
  • Loading branch information
donnybeelo committed Aug 19, 2024
1 parent b7bf811 commit f3e2581
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 0 additions & 3 deletions softpack_core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


import urllib.parse
from multiprocessing import Event
from multiprocessing.synchronize import Event as EventClass
from pathlib import Path

Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

0 comments on commit f3e2581

Please sign in to comment.