Skip to content

Commit 92271fe

Browse files
committed
test(ffe): cover customer CDN endpoint source mode
1 parent a69fc66 commit 92271fe

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

tests/parametric/test_ffe/test_source_modes.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from utils import features, scenarios
1414
from utils.dd_constants import RemoteConfigApplyState
1515
from utils.docker_fixtures import TestAgentAPI
16-
from utils.docker_fixtures._mock_cdn import MockCDNServer
16+
from utils.docker_fixtures._mock_cdn import MockCDNServer, MockCDNStatus
1717

1818
parametrize = pytest.mark.parametrize
1919
pytest_plugins = ["utils.docker_fixtures._mock_cdn"]
@@ -87,16 +87,17 @@ def library_env(request: pytest.FixtureRequest, mock_cdn: MockCDNServer) -> dict
8787

8888

8989
def _wait_for_status(
90-
mock_cdn: MockCDNServer, predicate: Callable[[dict[str, Any]], bool], description: str
91-
) -> dict[str, Any]:
92-
last_status: dict[str, Any] = {}
90+
mock_cdn: MockCDNServer, predicate: Callable[[MockCDNStatus], bool], description: str
91+
) -> MockCDNStatus:
92+
last_status: MockCDNStatus | None = None
9393
for _ in range(MOCK_STATUS_ATTEMPTS):
9494
last_status = mock_cdn.status()
9595
if predicate(last_status):
9696
return last_status
9797
time.sleep(MOCK_STATUS_INTERVAL_SECONDS)
9898

9999
pytest.fail(f"mock CDN status did not reach expected state: {description}; status={last_status}", pytrace=False)
100+
raise AssertionError("unreachable")
100101

101102

102103
def _evaluate(test_library: APMLibrary) -> dict[str, Any]:
@@ -183,6 +184,26 @@ def test_default_cdn_positive(self, test_library: APMLibrary, mock_cdn: MockCDNS
183184
assert status["fixture"] == "valid_control"
184185
assert status["last_source_mode"] == "cdn"
185186

187+
@parametrize(
188+
"library_env",
189+
[{"source_mode": None, "fixture": "valid_control", "base_url_form": "endpoint"}],
190+
indirect=True,
191+
)
192+
def test_customer_http_endpoint_default_cdn_positive(
193+
self, test_library: APMLibrary, mock_cdn: MockCDNServer
194+
) -> None:
195+
assert test_library.ffe_start(), "failed to start FFE provider with customer HTTP endpoint override"
196+
_assert_expected_value(_evaluate(test_library))
197+
198+
status = _wait_for_status(
199+
mock_cdn,
200+
lambda current: current["requests_total"] > 0 and current["last_status_code"] == 200,
201+
"customer HTTP endpoint request",
202+
)
203+
assert status["fixture"] == "valid_control"
204+
assert status["last_path"] == "/mock/ufc/config"
205+
assert status["last_source_mode"] == "cdn"
206+
186207
@parametrize(
187208
"library_env",
188209
[{"source_mode": "cdn", "fixture": "missing_auth_cold", "api_key": None}],
@@ -367,6 +388,8 @@ def test_mock_cdn_status_is_metadata_only(self, mock_cdn: MockCDNServer) -> None
367388
"requests_total",
368389
"in_flight",
369390
"max_in_flight",
391+
"last_path",
392+
"last_query",
370393
"last_if_none_match",
371394
"last_auth_present",
372395
"last_source_mode",

utils/docker_fixtures/_mock_cdn.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class MockCDNStatus(TypedDict):
5656
requests_total: int
5757
in_flight: int
5858
max_in_flight: int
59+
last_path: str | None
60+
last_query: str | None
5961
last_if_none_match: str | None
6062
last_auth_present: bool
6163
last_source_mode: str | None
@@ -70,6 +72,8 @@ def __init__(self) -> None:
7072
self.requests_total = 0
7173
self.in_flight = 0
7274
self.max_in_flight = 0
75+
self.last_path: str | None = None
76+
self.last_query: str | None = None
7377
self.last_if_none_match: str | None = None
7478
self.last_auth_present = False
7579
self.last_source_mode: str | None = None
@@ -83,6 +87,8 @@ def reset(self) -> None:
8387
self.requests_total = 0
8488
self.in_flight = 0
8589
self.max_in_flight = 0
90+
self.last_path = None
91+
self.last_query = None
8692
self.last_if_none_match = None
8793
self.last_auth_present = False
8894
self.last_source_mode = None
@@ -112,6 +118,8 @@ def record_request(self, headers: Mapping[str, str], path: str) -> tuple[str, in
112118
self.requests_total += 1
113119
self.in_flight += 1
114120
self.max_in_flight = max(self.max_in_flight, self.in_flight)
121+
self.last_path = parsed.path
122+
self.last_query = parsed.query or None
115123
self.last_if_none_match = headers.get("If-None-Match")
116124
self.last_auth_present = _has_auth(headers)
117125
self.last_source_mode = source_mode
@@ -135,6 +143,8 @@ def status(self) -> MockCDNStatus:
135143
"requests_total": self.requests_total,
136144
"in_flight": self.in_flight,
137145
"max_in_flight": self.max_in_flight,
146+
"last_path": self.last_path,
147+
"last_query": self.last_query,
138148
"last_if_none_match": self.last_if_none_match,
139149
"last_auth_present": self.last_auth_present,
140150
"last_source_mode": self.last_source_mode,
@@ -184,14 +194,15 @@ def log_message(self, _format: str, *_args: object) -> None:
184194
return
185195

186196
def _handle_config(self) -> None:
187-
fixture, sequence_index = self.server.state.record_request(dict(self.headers), self.path)
197+
request_headers = dict(self.headers)
198+
fixture, sequence_index = self.server.state.record_request(request_headers, self.path)
188199
try:
189200
if fixture == "delayed_no_overlap":
190201
time.sleep(DELAYED_RESPONSE_SECONDS)
191202

192203
status_code, body, headers = _response_for_fixture(
193204
fixture=fixture,
194-
has_auth=_has_auth(self.headers),
205+
has_auth=_has_auth(request_headers),
195206
if_none_match=self.headers.get("If-None-Match"),
196207
sequence_index=sequence_index,
197208
)

0 commit comments

Comments
 (0)