1111from __future__ import annotations
1212
1313import json
14+ import time
15+ import urllib .error
1416import urllib .request
1517
1618from common .cli_runner import CliResult , run_rocm
@@ -90,7 +92,7 @@ def setup_localhost_model(self):
9092
9193 @keyword ("a model is being served on GPU" )
9294 def setup_gpu_model (self ):
93- """Start a real model server using rocm serve."""
95+ """Start a real model server using rocm serve, waiting for readiness ."""
9496 self ._serve_result = run_rocm (
9597 "serve" ,
9698 "Qwen/Qwen2.5-1.5B-Instruct" ,
@@ -104,6 +106,7 @@ def setup_gpu_model(self):
104106 )
105107 self ._endpoint = "http://127.0.0.1:11435/v1"
106108 self ._model_name = "Qwen/Qwen2.5-1.5B-Instruct"
109+ self ._wait_for_endpoint ()
107110 logger .info (f"Model served at { self ._endpoint } " )
108111
109112 @keyword ("a model is served in the background" )
@@ -170,6 +173,23 @@ def user_serves_default_engine(self):
170173 self ._endpoint = "http://127.0.0.1:11435/v1"
171174 self ._model_name = "Qwen/Qwen2.5-1.5B-Instruct"
172175
176+ def _wait_for_endpoint (self , timeout : int = 120 ):
177+ """Poll the endpoint until it responds or timeout is reached."""
178+ assert self ._endpoint is not None , "No endpoint configured"
179+ url = f"{ self ._endpoint } /models"
180+ deadline = time .time () + timeout
181+ while time .time () < deadline :
182+ try :
183+ req = urllib .request .Request (url )
184+ with urllib .request .urlopen (req , timeout = 5 ) as resp :
185+ if resp .status == 200 :
186+ logger .info (f"Endpoint ready at { self ._endpoint } " )
187+ return
188+ except (urllib .error .URLError , OSError ):
189+ pass
190+ time .sleep (5 )
191+ raise AssertionError (f"Endpoint { self ._endpoint } not ready after { timeout } s" )
192+
173193 @keyword ("the dashboard offers to use the detected endpoint" )
174194 def dashboard_offers_endpoint (self ):
175195 """Simulate the TUI detecting a local endpoint.
0 commit comments