From 4f939ed54061d73336d949a8b1ba3af83b634212 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 09:40:13 -0800 Subject: [PATCH 1/2] port retry-after fix into corehttp --- sdk/core/corehttp/CHANGELOG.md | 6 ++++++ .../corehttp/corehttp/runtime/policies/_utils.py | 2 +- .../tests/async_tests/test_retry_policy_async.py | 2 +- sdk/core/corehttp/tests/test_retry_policy.py | 4 +++- sdk/core/corehttp/tests/test_utils.py | 12 ++++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sdk/core/corehttp/CHANGELOG.md b/sdk/core/corehttp/CHANGELOG.md index 479ece7be240..50e2f169162e 100644 --- a/sdk/core/corehttp/CHANGELOG.md +++ b/sdk/core/corehttp/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.0.0b5 (2024-02-29) + +### Other Changes + +- Accept float for `retry_after` header. + ## 1.0.0b4 (2024-02-23) ### Other Changes diff --git a/sdk/core/corehttp/corehttp/runtime/policies/_utils.py b/sdk/core/corehttp/corehttp/runtime/policies/_utils.py index 192e82bad680..b9510c2bf8e6 100644 --- a/sdk/core/corehttp/corehttp/runtime/policies/_utils.py +++ b/sdk/core/corehttp/corehttp/runtime/policies/_utils.py @@ -61,7 +61,7 @@ def parse_retry_after(retry_after: str) -> float: """ delay: float # Using the Mypy recommendation to use float for "int or float" try: - delay = int(retry_after) + delay = float(retry_after) except ValueError: # Not an integer? Try HTTP date retry_date = _parse_http_date(retry_after) diff --git a/sdk/core/corehttp/tests/async_tests/test_retry_policy_async.py b/sdk/core/corehttp/tests/async_tests/test_retry_policy_async.py index 6c3a3fd0dbec..8a6a1e69b822 100644 --- a/sdk/core/corehttp/tests/async_tests/test_retry_policy_async.py +++ b/sdk/core/corehttp/tests/async_tests/test_retry_policy_async.py @@ -57,7 +57,7 @@ def test_retry_types(): @pytest.mark.parametrize( "retry_after_input,http_response", - product(["0", "800", "1000", "1200"], ASYNC_HTTP_RESPONSES), + product(["0", "800", "1000", "1200", "0.9"], ASYNC_HTTP_RESPONSES), ) def test_retry_after(retry_after_input, http_response): retry_policy = AsyncRetryPolicy() diff --git a/sdk/core/corehttp/tests/test_retry_policy.py b/sdk/core/corehttp/tests/test_retry_policy.py index 1d4ce598fad8..7f6d68f27839 100644 --- a/sdk/core/corehttp/tests/test_retry_policy.py +++ b/sdk/core/corehttp/tests/test_retry_policy.py @@ -54,7 +54,9 @@ def test_retry_types(): assert backoff_time == 4 -@pytest.mark.parametrize("retry_after_input,http_response", product(["0", "800", "1000", "1200"], HTTP_RESPONSES)) +@pytest.mark.parametrize( + "retry_after_input,http_response", product(["0", "800", "1000", "1200", "0.9"], HTTP_RESPONSES) +) def test_retry_after(retry_after_input, http_response): retry_policy = RetryPolicy() request = HttpRequest("GET", "http://localhost") diff --git a/sdk/core/corehttp/tests/test_utils.py b/sdk/core/corehttp/tests/test_utils.py index 4d997a6c3288..0a282b10317c 100644 --- a/sdk/core/corehttp/tests/test_utils.py +++ b/sdk/core/corehttp/tests/test_utils.py @@ -8,6 +8,7 @@ import pytest from corehttp.utils import case_insensitive_dict from corehttp.utils._utils import get_running_async_lock +from corehttp.runtime.policies._utils import parse_retry_after @pytest.fixture() @@ -124,3 +125,14 @@ async def test_get_running_async_module_asyncio(): def test_get_running_async_module_sync(): with pytest.raises(RuntimeError): get_running_async_lock() + + +def test_parse_retry_after(): + ret = parse_retry_after("100") + assert ret == 100 + ret = parse_retry_after("Fri, 1 Oct 2100 00:00:00 GMT") + assert ret > 0 + ret = parse_retry_after("0") + assert ret == 0 + ret = parse_retry_after("0.9") + assert ret == 0.9 From 1b38f1fec3849d4b57509a8658616f70b1aa3c50 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 10:26:56 -0800 Subject: [PATCH 2/2] update --- sdk/core/corehttp/corehttp/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/corehttp/corehttp/_version.py b/sdk/core/corehttp/corehttp/_version.py index e8391849fa9d..34b338b446b9 100644 --- a/sdk/core/corehttp/corehttp/_version.py +++ b/sdk/core/corehttp/corehttp/_version.py @@ -9,4 +9,4 @@ # regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b4" +VERSION = "1.0.0b5"