1- import asyncio
21import importlib .resources
32import json
43import os
54
65import firecrest as f7t
76import pytest
87
9- from swiss_ai_model_launch .cli .healthcheck import ModelHealth , check_model_health
108from swiss_ai_model_launch .launchers .firecrest_launcher import FirecRESTLauncher
119from swiss_ai_model_launch .launchers .launch_request import LaunchRequest
12- from swiss_ai_model_launch . launchers . launcher import JobStatus
10+ from tests . integration . utils import wait_for_job_running , wait_for_model_healthy
1311
1412_LAUNCH_TIMEOUT = 60
1513_HEALTH_TIMEOUT = 120
@@ -74,42 +72,6 @@ def cscs_api_key(env: dict[str, str]) -> str:
7472 return env ["SML_CSCS_API_KEY" ]
7573
7674
77- async def _wait_for_job_running (
78- launcher : FirecRESTLauncher ,
79- job_id : int ,
80- timeout_min : int ,
81- poll_interval_seconds : int = 15 ,
82- ) -> None :
83- deadline = asyncio .get_event_loop ().time () + timeout_min * 60
84- while asyncio .get_event_loop ().time () < deadline :
85- await asyncio .sleep (poll_interval_seconds )
86- status = await launcher .get_job_status (job_id )
87- print (f"[job { job_id } ] status: { status .value } " )
88- if status == JobStatus .RUNNING :
89- return
90- if status == JobStatus .TIMEOUT :
91- pytest .fail (f"Job { job_id } timed out before becoming RUNNING." )
92- pytest .fail (f"Job { job_id } didn't reach RUNNING within { timeout_min } mins." )
93-
94-
95- async def _wait_for_model_healthy (
96- served_model_name : str ,
97- api_key : str ,
98- timeout_min : int ,
99- poll_interval_seconds : int = 30 ,
100- ) -> None :
101- deadline = asyncio .get_event_loop ().time () + timeout_min * 60
102- while asyncio .get_event_loop ().time () < deadline :
103- await asyncio .sleep (poll_interval_seconds )
104- health = await check_model_health (served_model_name , api_key )
105- print (f"[{ served_model_name } ] health: { health .value } " )
106- if health == ModelHealth .HEALTHY :
107- return
108- pytest .fail (
109- f"Model '{ served_model_name } ' didn't become HEALTHY within { timeout_min } mins."
110- )
111-
112-
11375@pytest .mark .parametrize ("launch_request" , _LAUNCH_REQUESTS ) # type: ignore[misc]
11476async def test_launch_apertus_and_health (
11577 launcher : FirecRESTLauncher ,
@@ -123,7 +85,7 @@ async def test_launch_apertus_and_health(
12385 assert served_model_name
12486
12587 try :
126- await _wait_for_job_running (launcher , job_id , _LAUNCH_TIMEOUT )
127- await _wait_for_model_healthy (served_model_name , cscs_api_key , _HEALTH_TIMEOUT )
88+ await wait_for_job_running (launcher , job_id , _LAUNCH_TIMEOUT )
89+ await wait_for_model_healthy (served_model_name , cscs_api_key , _HEALTH_TIMEOUT )
12890 finally :
12991 await launcher .cancel_job (job_id )
0 commit comments