File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
integrations/launch_darkly
tests/unit/integrations/launch_darkly Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
from integrations .launch_darkly import types as ld_types
11
11
from integrations .launch_darkly .constants import (
12
+ BACKOFF_DEFAULT_RETRY_AFTER_SECONDS ,
12
13
BACKOFF_MAX_RETRIES ,
13
14
LAUNCH_DARKLY_API_BASE_URL ,
14
15
LAUNCH_DARKLY_API_ITEM_COUNT_LIMIT_PER_PAGE ,
@@ -41,6 +42,9 @@ def _get_retry_after(exc: RequestException) -> float | None:
41
42
return float (retry_after )
42
43
if ratelimit_reset := headers .get ("X-Ratelimit-Reset" ):
43
44
return float (ratelimit_reset ) - timezone_now ().timestamp ()
45
+ # We have no retry information, use a default backoff time
46
+ # of 10 seconds as per LD documentation.
47
+ return BACKOFF_DEFAULT_RETRY_AFTER_SECONDS
44
48
return None
45
49
46
50
def _wait_gen () -> Generator [float , None , None ]:
Original file line number Diff line number Diff line change 8
8
LAUNCH_DARKLY_IMPORTED_DEFAULT_TAG_LABEL = "Imported"
9
9
10
10
BACKOFF_MAX_RETRIES = 5
11
+ BACKOFF_DEFAULT_RETRY_AFTER_SECONDS = 10
Original file line number Diff line number Diff line change @@ -325,3 +325,39 @@ def test_launch_darkly_client__rate_limit_invalid_response__raises_expected(
325
325
# When & Then
326
326
with pytest .raises (HTTPError ):
327
327
client .get_project (project_key = project_key )
328
+
329
+
330
+ def test_launch_darkly_client__rate_limit_no_headers__waits_expected (
331
+ request : pytest .FixtureRequest ,
332
+ mocker : MockerFixture ,
333
+ requests_mock : RequestsMockerFixture ,
334
+ ) -> None :
335
+ # Given
336
+ token = "test-token"
337
+ project_key = "test-project-key"
338
+
339
+ mocker .patch (
340
+ "integrations.launch_darkly.client.BACKOFF_DEFAULT_RETRY_AFTER_SECONDS" ,
341
+ new = 0.1 ,
342
+ )
343
+
344
+ example_response_content = (
345
+ request .path .parent / "example_api_responses/getProject.json"
346
+ ).read_text ()
347
+ expected_result = json .loads (example_response_content )
348
+
349
+ requests_mock .get (
350
+ "https://app.launchdarkly.com/api/v2/projects/test-project-key" ,
351
+ [
352
+ {"status_code" : 429 },
353
+ {"status_code" : 200 , "text" : example_response_content },
354
+ ],
355
+ )
356
+
357
+ client = LaunchDarklyClient (token = token )
358
+
359
+ # When
360
+ result = client .get_project (project_key = project_key )
361
+
362
+ # Then
363
+ assert result == expected_result
You can’t perform that action at this time.
0 commit comments