1919import os
2020import re
2121import subprocess
22+ import time
2223from datetime import datetime
2324from enum import Enum
2425from pathlib import Path
2526from typing import Dict , List , NamedTuple , Optional
2627
28+ import requests
2729from _pytest .nodes import Item
2830from _pytest .python import Function
2931from defs .trt_test_alternative import (check_output , popen , print_error ,
@@ -316,6 +318,19 @@ class PerfDisaggScriptTestCmds(NamedTuple):
316318 client_cmd : List [str ]
317319 benchmark_cmd : List [str ]
318320
321+ def wait_for_endpoint_ready (self , url : str , timeout : int = 600 ):
322+ start = time .monotonic ()
323+ while time .monotonic () - start < timeout :
324+ try :
325+ time .sleep (1 )
326+ if requests .get (url ).status_code == 200 :
327+ print (f"endpoint { url } is ready" )
328+ return
329+ except Exception as err :
330+ print (f"endpoint { url } is not ready, with exception: { err } " )
331+ print_error (
332+ f"Endpoint { url } did not become ready within { timeout } seconds" )
333+
319334 def run_cmd (self , cmd_idx : int , venv ) -> str :
320335 output = ""
321336 try :
@@ -340,6 +355,9 @@ def run_cmd(self, cmd_idx: int, venv) -> str:
340355 stderr = subprocess .STDOUT ,
341356 env = venv ._new_env ,
342357 shell = True ) as server_proc ):
358+ self .wait_for_endpoint_ready (
359+ f"http://localhost:8000/health" ,
360+ timeout = 1800 ) # 30 minutes for large models
343361 check_output (self .client_cmd , env = venv ._new_env )
344362 output += check_output (self .benchmark_cmd , env = venv ._new_env )
345363 finally :
0 commit comments