Skip to content

Commit b34588b

Browse files
committed
Add retry to test
1 parent 236feb9 commit b34588b

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

sagemaker-serve/tests/integ/test_huggingface_integration.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import uuid
1717
import pytest
1818
import logging
19+
import time
20+
from botocore.exceptions import ClientError
1921

2022
from sagemaker.serve.model_builder import ModelBuilder
2123
from sagemaker.serve.utils.types import ModelServer
@@ -116,11 +118,26 @@ def make_prediction(core_endpoint):
116118
"inputs": "What are falcons?",
117119
"parameters": {"max_new_tokens": 32},
118120
}
119-
120-
result = core_endpoint.invoke(
121-
body=json.dumps(test_data),
122-
content_type="application/json"
123-
)
121+
122+
# Retry logic to handle endpoint propagation delay in CodeBuild
123+
max_retries = 5
124+
for attempt in range(max_retries):
125+
try:
126+
result = core_endpoint.invoke(
127+
body=json.dumps(test_data),
128+
content_type="application/json"
129+
)
130+
break
131+
except ClientError as e:
132+
if e.response['Error']['Code'] == 'ValidationException' and 'not found' in str(e):
133+
if attempt < max_retries - 1:
134+
wait_time = 2 ** attempt # Exponential backoff: 1, 2, 4, 8 seconds
135+
logger.warning(f"Endpoint not found, retrying in {wait_time}s (attempt {attempt + 1}/{max_retries})")
136+
time.sleep(wait_time)
137+
else:
138+
raise
139+
else:
140+
raise
124141

125142
# Decode the output of the invocation and print the result
126143
prediction = json.loads(result.body.read().decode('utf-8'))

0 commit comments

Comments
 (0)