From 122d89ab0e5d6874288bc0c9c4aeac0f0b380b43 Mon Sep 17 00:00:00 2001 From: "Matthew M. Keeler" Date: Tue, 30 Jan 2024 09:51:26 -0500 Subject: [PATCH 1/4] chore: Enable server-side-polling in contract tests (#260) --- contract-tests/client_entity.py | 6 ++++++ contract-tests/service.py | 1 + 2 files changed, 7 insertions(+) diff --git a/contract-tests/client_entity.py b/contract-tests/client_entity.py index 702a6a90..9cb4e0ff 100644 --- a/contract-tests/client_entity.py +++ b/contract-tests/client_entity.py @@ -30,6 +30,12 @@ def __init__(self, tag, config): if streaming.get("baseUri") is not None: opts["stream_uri"] = streaming["baseUri"] _set_optional_time_prop(streaming, "initialRetryDelayMs", opts, "initial_reconnect_delay") + else: + opts['stream'] = False + polling = config["polling"] + if polling.get("baseUri") is not None: + opts["base_uri"] = polling["baseUri"] + _set_optional_time_prop(polling, "pollIntervalMs", opts, "poll_interval") if config.get("events") is not None: events = config["events"] diff --git a/contract-tests/service.py b/contract-tests/service.py index 16a078ad..507354c4 100644 --- a/contract-tests/service.py +++ b/contract-tests/service.py @@ -61,6 +61,7 @@ def status(): body = { 'capabilities': [ 'server-side', + 'server-side-polling', 'all-flags-with-reasons', 'all-flags-client-side-only', 'all-flags-details-only-for-tracked-flags', From 38dc10b4444bffb59ce4c9b92cb92407c48ef375 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Tue, 30 Jan 2024 10:01:06 -0500 Subject: [PATCH 2/4] fix: Gzip header should only be set on polling --- Makefile | 4 ++-- ldclient/impl/datasource/feature_requester.py | 1 + ldclient/impl/http.py | 3 +-- testing/impl/datasource/test_streaming.py | 1 - testing/impl/events/test_event_processor.py | 8 -------- 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 6a42c00a..7c6ec60c 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ install-contract-tests-deps: poetry install --with contract-tests .PHONY: start-contract-test-service -start-contract-test-service: +start-contract-test-service: install-contract-tests-deps @cd contract-tests && poetry run python service.py $(PORT) .PHONY: start-contract-test-service-bg @@ -71,7 +71,7 @@ run-contract-tests: .PHONY: contract-tests contract-tests: #! Run the contract test harness -contract-tests: install-contract-tests-deps start-contract-test-service-bg run-contract-tests +contract-tests: start-contract-test-service-bg run-contract-tests # # SSE contract test service commands diff --git a/ldclient/impl/datasource/feature_requester.py b/ldclient/impl/datasource/feature_requester.py index 98d07bb8..b5f390bc 100644 --- a/ldclient/impl/datasource/feature_requester.py +++ b/ldclient/impl/datasource/feature_requester.py @@ -29,6 +29,7 @@ def get_all_data(self): uri = self._poll_uri hdrs = _headers(self._config) cache_entry = self._cache.get(uri) + hdrs['Accept-Encoding'] = 'gzip' if cache_entry is not None: hdrs['If-None-Match'] = cache_entry.etag r = self._http.request('GET', uri, diff --git a/ldclient/impl/http.py b/ldclient/impl/http.py index 9ebb0102..5fea123d 100644 --- a/ldclient/impl/http.py +++ b/ldclient/impl/http.py @@ -19,8 +19,7 @@ def _application_header_value(application: dict) -> str: def _base_headers(config): headers = {'Authorization': config.sdk_key or '', - 'User-Agent': 'PythonClient/' + VERSION, - 'Accept-Encoding': 'gzip' + 'User-Agent': 'PythonClient/' + VERSION } app_value = _application_header_value(config.application) diff --git a/testing/impl/datasource/test_streaming.py b/testing/impl/datasource/test_streaming.py index f18a43e4..8e449d25 100644 --- a/testing/impl/datasource/test_streaming.py +++ b/testing/impl/datasource/test_streaming.py @@ -39,7 +39,6 @@ def test_request_properties(): assert req.method == 'GET' assert req.headers.get('Authorization') == 'sdk-key' assert req.headers.get('User-Agent') == 'PythonClient/' + VERSION - assert req.headers['Accept-Encoding'] == 'gzip' assert req.headers.get('X-LaunchDarkly-Wrapper') is None assert req.headers.get('X-LaunchDarkly-Tags') is None diff --git a/testing/impl/events/test_event_processor.py b/testing/impl/events/test_event_processor.py index 3c4ac1f8..15e95bba 100644 --- a/testing/impl/events/test_event_processor.py +++ b/testing/impl/events/test_event_processor.py @@ -277,14 +277,6 @@ def test_sdk_key_is_sent(): assert mock_http.request_headers.get('Authorization') == 'SDK_KEY' -def test_default_headers_are_send(): - with DefaultTestProcessor() as ep: - ep.send_event(EventInputIdentify(timestamp, context)) - ep.flush() - ep._wait_until_inactive() - - assert mock_http.request_headers.get('Accept-Encoding') == 'gzip' - def test_wrapper_header_not_sent_when_not_set(): with DefaultTestProcessor() as ep: ep.send_event(EventInputIdentify(timestamp, context)) From e4201068db0218dfad6bab3f7def89a66dd89cac Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Tue, 30 Jan 2024 09:34:53 -0500 Subject: [PATCH 3/4] chore: Enable gzip polling contract tests --- contract-tests/service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/contract-tests/service.py b/contract-tests/service.py index 507354c4..4afe8612 100644 --- a/contract-tests/service.py +++ b/contract-tests/service.py @@ -69,6 +69,7 @@ def status(): 'context-type', 'secure-mode-hash', 'tags', + 'polling-gzip' ] } return (json.dumps(body), 200, {'Content-type': 'application/json'}) From 1dcc528347e59f483960e253a5620da9c885e893 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Tue, 30 Jan 2024 14:32:30 -0500 Subject: [PATCH 4/4] Re-trigger workflow