Skip to content

Commit 7afac12

Browse files
committed
Add TODO and timeout errors test
1 parent 063ed28 commit 7afac12

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

packages/smithy-core/tests/functional/test_retries.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from asyncio import gather, sleep
55

66
import pytest
7-
from smithy_core.exceptions import CallError, RetryError
7+
from smithy_core.exceptions import CallError, ClientTimeoutError, RetryError
88
from smithy_core.interfaces import retries as retries_interface
99
from smithy_core.retries import (
1010
ExponentialBackoffJitterType,
@@ -14,29 +14,35 @@
1414
)
1515

1616

17+
# TODO: Refactor this to use a smithy-testing generated client
1718
async def retry_operation(
1819
strategy: retries_interface.RetryStrategy,
19-
status_codes: list[int],
20+
responses: list[int | Exception],
2021
) -> tuple[str, int]:
2122
token = strategy.acquire_initial_retry_token()
22-
responses = iter(status_codes)
23+
response_iter = iter(responses)
2324

2425
while True:
2526
if token.retry_delay:
2627
await sleep(token.retry_delay)
2728

28-
status_code = next(responses)
29+
response = next(response_iter)
2930
attempt = token.retry_count + 1
3031

31-
if status_code == 200:
32+
# Success case
33+
if response == 200:
3234
strategy.record_success(token=token)
3335
return "success", attempt
3436

35-
error = CallError(
36-
fault="server" if status_code >= 500 else "client",
37-
message=f"HTTP {status_code}",
38-
is_retry_safe=status_code >= 500,
39-
)
37+
# Error case - either status code or exception
38+
if isinstance(response, Exception):
39+
error = response
40+
else:
41+
error = CallError(
42+
fault="server" if response >= 500 else "client",
43+
message=f"HTTP {response}",
44+
is_retry_safe=response >= 500,
45+
)
4046

4147
try:
4248
token = strategy.refresh_retry_token_for_retry(
@@ -131,3 +137,17 @@ async def test_retry_quota_shared_across_concurrent_operations():
131137
assert result1 == ("success", 3)
132138
assert result2 == ("success", 2)
133139
assert quota.available_capacity == 495
140+
141+
142+
async def test_retry_quota_handles_timeout_errors():
143+
quota = StandardRetryQuota(initial_capacity=500)
144+
strategy = StandardRetryStrategy(max_attempts=3, retry_quota=quota)
145+
146+
timeout1 = ClientTimeoutError()
147+
timeout2 = ClientTimeoutError()
148+
149+
result, attempts = await retry_operation(strategy, [timeout1, timeout2, 200])
150+
151+
assert result == "success"
152+
assert attempts == 3
153+
assert quota.available_capacity == 490

0 commit comments

Comments
 (0)