Skip to content

Commit ea85e63

Browse files
committed
fix: Add https readiness check for rest-registry tests
Signed-off-by: ntkathole <[email protected]>
1 parent 406ebcb commit ea85e63

File tree

1 file changed

+44
-0
lines changed
  • sdk/python/tests/integration/registration/rest_api

1 file changed

+44
-0
lines changed

sdk/python/tests/integration/registration/rest_api/conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
from pathlib import Path
34

45
import pytest
@@ -37,6 +38,44 @@ def get(self, endpoint, params=None):
3738
return requests.get(url, params=params, verify=False)
3839

3940

41+
def _wait_for_http_ready(route_url: str, timeout: int = 180, interval: int = 5) -> None:
42+
"""
43+
Poll the HTTP endpoint until it returns a non-502 response.
44+
45+
After Pod/CR readiness is confirmed, the backend behind the ingress may
46+
still be initializing. This helper avoids the race condition where tests
47+
start before the Feast server is ready, causing all requests to return 502.
48+
"""
49+
health_url = f"{route_url}/api/v1/projects"
50+
deadline = time.time() + timeout
51+
last_status = None
52+
53+
print(
54+
f"\n Waiting for HTTP endpoint to become ready (timeout={timeout}s): {health_url}"
55+
)
56+
57+
while time.time() < deadline:
58+
try:
59+
resp = requests.get(health_url, timeout=10, verify=False)
60+
last_status = resp.status_code
61+
if resp.status_code != 502:
62+
print(f" HTTP endpoint is ready (status={resp.status_code})")
63+
return
64+
print(
65+
f" HTTP endpoint returned {resp.status_code}, retrying in {interval}s..."
66+
)
67+
except requests.exceptions.RequestException as exc:
68+
last_status = str(exc)
69+
print(f" HTTP request failed ({exc}), retrying in {interval}s...")
70+
71+
time.sleep(interval)
72+
73+
raise RuntimeError(
74+
f"HTTP endpoint {health_url} did not become ready within {timeout}s "
75+
f"(last status: {last_status})"
76+
)
77+
78+
4079
@pytest.fixture(scope="session")
4180
def feast_rest_client():
4281
# Load kubeconfig and initialize Kubernetes client
@@ -142,6 +181,11 @@ def feast_rest_client():
142181
if not route_url:
143182
raise RuntimeError("Route URL could not be fetched.")
144183

184+
# Wait for the HTTP endpoint to become ready before running tests.
185+
# Pod/CR readiness does not guarantee the backend is serving traffic;
186+
# the ingress may return 502 while the Feast server is still starting.
187+
_wait_for_http_ready(route_url)
188+
145189
print(f"\n Connected to Feast REST at: {route_url}")
146190
yield FeastRestClient(route_url)
147191

0 commit comments

Comments
 (0)