Skip to content

Commit b5db16f

Browse files
committed
updated based on ai feedback
1 parent 702c713 commit b5db16f

File tree

2 files changed

+51
-39
lines changed

2 files changed

+51
-39
lines changed

tests/serve/test_dynamo_serve.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -224,43 +224,51 @@ def test_serve_deployment(deployment_graph_test, request, runtime_services):
224224
response = requests.post(url, json=payload.payload, timeout=300)
225225
except Exception as e:
226226
# pytest.fail(f"Request failed: {str(e)}")
227-
logger.warning(e)
227+
logger.warning("Request failed: %s", e)
228228
time.sleep(5)
229229
continue
230-
logger.info(f"Response{response}")
231-
if (
232-
response.status_code == 500
233-
and "no instances" in response.json()["error"]
234-
):
235-
time.sleep(5)
236-
continue
237-
238-
if (
239-
response.status_code == 404
240-
and "Model not found" in response.json()["error"]
241-
):
242-
time.sleep(5)
243-
continue
244-
230+
logger.info("Response%r", response)
231+
if response.status_code == 500:
232+
error = response.json().get("error", "")
233+
if "no instances" in error:
234+
logger.warning("Retrying due to no instances available")
235+
time.sleep(5)
236+
continue
237+
if response.status_code == 404:
238+
error = response.json().get("error", "")
239+
if "Model not found" in error:
240+
logger.warning("Retrying due to model not found")
241+
time.sleep(5)
242+
continue
245243
# Process the response
246244
if response.status_code != 200:
245+
logger.error(
246+
"Service returned status code %s: %s",
247+
response.status_code,
248+
response.text,
249+
)
247250
pytest.fail(
248-
f"Service returned status code {response.status_code}: {response.text}"
251+
"Service returned status code %s: %s"
252+
% (response.status_code, response.text)
249253
)
250254
else:
251255
break
252256
else:
257+
logger.error(
258+
"Service did not return a successful response within %s s",
259+
deployment_graph.timeout,
260+
)
253261
pytest.fail(
254-
f"Service did not return a successful response within "
255-
f"{deployment_graph.timeout} s"
262+
"Service did not return a successful response within %s s"
263+
% deployment_graph.timeout
256264
)
257265

258266
content = deployment_graph.response_handler(response)
259267

260-
logger.info(f"Received Content: {content}")
268+
logger.info("Received Content: %s", content)
261269

262270
# Check for expected responses
263271
assert content, "Empty response content"
264272

265273
for expected in payload.expected_response:
266-
assert expected in content, f"Expected '{expected}' not found in response"
274+
assert expected in content, "Expected '%s' not found in response" % expected

tests/utils/managed_process.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def _start_process(self):
9090
assert self._log_path
9191

9292
self._logger.info(
93-
f"Running command: {' '.join(self.command)} in {self.working_dir or os.getcwd()}"
93+
"Running command: %s in %s",
94+
" ".join(self.command),
95+
self.working_dir or os.getcwd(),
9496
)
9597

9698
stdin = subprocess.DEVNULL
@@ -139,7 +141,7 @@ def _remove_directory(self, path: str) -> None:
139141
try:
140142
shutil.rmtree(path, ignore_errors=True)
141143
except (OSError, IOError) as e:
142-
self._logger.warning(f"Warning: Failed to remove directory {path}: {e}")
144+
self._logger.warning("Warning: Failed to remove directory %s: %s", path, e)
143145

144146
def _check_ports(self, timeout):
145147
time_taken = 0
@@ -150,15 +152,15 @@ def _check_ports(self, timeout):
150152
def _check_port(self, port, timeout=30, sleep=0.1):
151153
"""Check if a port is open on localhost."""
152154
start_time = time.time()
153-
self._logger.info(f"Checking Port: {port}")
155+
self._logger.info("Checking Port: %s", port)
154156
while time.time() - start_time < timeout:
155157
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
156158
if s.connect_ex(("localhost", port)) == 0:
157-
self._logger.info(f"SUCCESS: Check Port:{port}")
159+
self._logger.info("SUCCESS: Check Port: %s", port)
158160
return time.time() - start_time
159161
time.sleep(sleep)
160-
self._logger.error(f"FAILED: Check Port: {port}")
161-
raise RuntimeError(f"FAILED: Check Port: {port}")
162+
self._logger.error("FAILED: Check Port: %s", port)
163+
raise RuntimeError("FAILED: Check Port: %s" % port)
162164

163165
def _check_urls(self, timeout):
164166
time_taken = 0
@@ -173,39 +175,41 @@ def _check_url(self, url, timeout=30, sleep=0.1):
173175
else:
174176
response_check = None
175177
start_time = time.time()
176-
self._logger.info(f"Checking URL {url}")
177-
while time.time() - start_time < timeout:
178+
self._logger.info("Checking URL %s", url)
179+
elapsed = 0
180+
while elapsed < timeout:
178181
try:
179-
response = requests.get(url, timeout=timeout)
182+
response = requests.get(url, timeout=timeout - elapsed)
180183
if response.status_code == 200:
181184
if response_check is None or response_check(response):
182-
self._logger.info(f"SUCCESS: Check URL:{url}")
185+
self._logger.info("SUCCESS: Check URL: %s", url)
183186
return time.time() - start_time
184187
except requests.RequestException as e:
185-
self._logger.warning(f"URL check failed: {e}")
188+
self._logger.warn("URL check failed: %s", e)
186189
time.sleep(sleep)
190+
elapsed = time.time() - start_time
187191

188-
self._logger.error(f"FAILED: Check URL: {url}")
189-
raise RuntimeError(f"FAILED: Check URL: {url}")
192+
self._logger.error("FAILED: Check URL: %s", url)
193+
raise RuntimeError("FAILED: Check URL: %s" % url)
190194

191195
def _terminate_existing(self):
192196
if self.terminate_existing:
193-
self._logger.info(f"Terminating Existing {self._command_name}")
197+
self._logger.info("Terminating Existing %s", self._command_name)
194198
for proc in psutil.process_iter(["name", "cmdline"]):
195199
if proc.name() == self._command_name or proc.name() in self.stragglers:
196200
self._terminate_process_tree(proc.pid)
197201

198202
def _terminate_process(self, process):
199203
try:
200-
self._logger.info(f"Terminating {process}")
204+
self._logger.info("Terminating %s", process)
201205
process.terminate()
202206
except psutil.AccessDenied:
203-
self._logger.warning(f"Access denied for PID {process.pid}")
207+
self._logger.warning("Access denied for PID %s", process.pid)
204208
except psutil.NoSuchProcess:
205-
self._logger.warning(f"PID {process.pid} no longer exists")
209+
self._logger.warning("PID %s no longer exists", process.pid)
206210
except psutil.TimeoutExpired:
207211
self._logger.warning(
208-
f"PID {process.pid} did not terminate before timeout, killing"
212+
"PID %s did not terminate before timeout, killing", process.pid
209213
)
210214
process.kill()
211215

0 commit comments

Comments
 (0)