Skip to content

Commit 9c302fa

Browse files
committed
[RAA-9996]-[GC]-[Adjust smoke test for APIM lower-env monitoring change]-[TH]
1 parent 2b1f4fb commit 9c302fa

1 file changed

Lines changed: 43 additions & 16 deletions

File tree

tests/smoke/test_status_endpoints.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import requests
44
from jsonpath_rw import parse
55

6+
# test runs normally in int and prod, status must report pass
7+
STRICT_STATUS_ENVS = {"int", "prod"}
8+
69

710
@pytest.mark.smoke_test
811
class TestStatusEndpoints:
@@ -14,25 +17,49 @@ def test_ping_endpoint(self, service_url):
1417
f"Actual response status code = {response.status_code}"
1518
)
1619

17-
def test_status_endpoint(self, service_url, status_endpoint_api_key):
20+
def test_status_endpoint(self, service_url, status_endpoint_api_key, environment):
1821
response = requests.get(
1922
f"{service_url}/_status", headers={"apikey": status_endpoint_api_key}
2023
)
21-
with check:
22-
assert response.status_code == 200, (
23-
f"UNEXPECTED RESPONSE: "
24-
f"Actual response status code = {response.status_code}"
24+
assert response.status_code == 200, (
25+
f"UNEXPECTED RESPONSE: "
26+
f"Actual response status code = {response.status_code}"
27+
)
28+
29+
# parse JSON response and extract the value
30+
response_json = response.json()
31+
top_level_statuses = [
32+
match.value for match in parse("$.status").find(response_json)
33+
]
34+
healthcheck_statuses = [
35+
match.value
36+
for match in parse('$.checks["healthcheckService:status"][*].status').find(
37+
response_json
2538
)
26-
with check:
27-
expression = parse("$.status")
28-
matches = [match.value for match in expression.find(response.json())]
29-
assert matches.count("pass") == 1, (
30-
f"UNEXPECTED RESPONSE: " f"Health check failed: $.status != 'pass'"
39+
]
40+
41+
# normal test behaviour in int and prod
42+
if environment in STRICT_STATUS_ENVS:
43+
assert (
44+
top_level_statuses.count("pass") == 1
45+
), "UNEXPECTED RESPONSE: Health check failed: $.status != 'pass'"
46+
assert healthcheck_statuses.count("pass") == len(healthcheck_statuses), (
47+
"UNEXPECTED RESPONSE: Health check failed: "
48+
"$.checks['healthcheckService:status'][*].status != 'pass'"
3149
)
32-
with check:
33-
expression = parse('$.checks["healthcheckService:status"][*].status')
34-
matches = [match.value for match in expression.find(response.json())]
35-
assert matches.count("pass") == len(matches), (
36-
f"UNEXPECTED RESPONSE: "
37-
f"Health check failed: $.checks['healthcheckService:status'][*].status)] != 'pass'"
50+
return
51+
52+
# Monitoring in lower environments is intentionally disabled, so making the test less strict.
53+
assert len(top_level_statuses) == 1 and top_level_statuses[0] in {
54+
"pass",
55+
"fail",
56+
}, "UNEXPECTED RESPONSE: $.status missing or invalid"
57+
assert len(healthcheck_statuses) >= 1 and all(
58+
status in {"pass", "fail"} for status in healthcheck_statuses
59+
), "UNEXPECTED RESPONSE: healthcheckService status missing or invalid"
60+
61+
# mark failures as expected behaviour
62+
if top_level_statuses[0] == "fail":
63+
pytest.xfail(
64+
"Known APIM lower-env behavior: _status may report fail outside int/prod"
3865
)

0 commit comments

Comments
 (0)