|
9 | 9 | from tests.utils import uuid_str |
10 | 10 |
|
11 | 11 |
|
12 | | -class TestFixedCountRetryStrategyAsync: |
13 | | - @pytest.mark.asyncio |
14 | | - @pytest.mark.local |
15 | | - async def test_retry_eligible_api_should_make_max_attempts_when_full_network_outage(self) -> None: |
16 | | - metrics_collector = MomentoLocalMetricsCollector() |
17 | | - middleware_args = MomentoLocalMiddlewareArgs( |
18 | | - request_id=str(uuid_str()), |
19 | | - test_metrics_collector=metrics_collector, |
20 | | - return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
21 | | - error_rpc_list=[MomentoRpcMethod.GET], |
22 | | - ) |
23 | | - cache_name = uuid_str() |
24 | | - |
25 | | - async with client_async_local(cache_name, middleware_args) as client: |
26 | | - response = await client.get(cache_name, "key") |
27 | | - |
28 | | - assert isinstance(response, CacheGet.Error) |
29 | | - assert response.error_code == MomentoErrorCode.SERVER_UNAVAILABLE |
30 | | - |
31 | | - retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.GET) |
32 | | - assert retry_count == 3 |
33 | | - |
34 | | - @pytest.mark.asyncio |
35 | | - @pytest.mark.local |
36 | | - async def test_non_retry_eligible_api_should_make_no_attempts_when_full_network_outage(self) -> None: |
37 | | - metrics_collector = MomentoLocalMetricsCollector() |
38 | | - middleware_args = MomentoLocalMiddlewareArgs( |
39 | | - request_id=str(uuid_str()), |
40 | | - test_metrics_collector=metrics_collector, |
41 | | - return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
42 | | - error_rpc_list=[MomentoRpcMethod.INCREMENT], |
43 | | - ) |
44 | | - cache_name = uuid_str() |
45 | | - |
46 | | - async with client_async_local(cache_name, middleware_args) as client: |
47 | | - response = await client.increment(cache_name, "key", 1) |
48 | | - |
49 | | - assert isinstance(response, CacheIncrement.Error) |
50 | | - assert response.error_code == MomentoErrorCode.SERVER_UNAVAILABLE |
51 | | - |
52 | | - retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.INCREMENT) |
53 | | - assert retry_count == 0 |
54 | | - |
55 | | - @pytest.mark.asyncio |
56 | | - @pytest.mark.local |
57 | | - async def test_retry_eligible_api_should_make_less_than_max_attempts_when_temporary_network_outage(self) -> None: |
58 | | - metrics_collector = MomentoLocalMetricsCollector() |
59 | | - middleware_args = MomentoLocalMiddlewareArgs( |
60 | | - request_id=str(uuid_str()), |
61 | | - test_metrics_collector=metrics_collector, |
62 | | - return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
63 | | - error_rpc_list=[MomentoRpcMethod.GET], |
64 | | - error_count=2, |
65 | | - ) |
66 | | - cache_name = uuid_str() |
67 | | - |
68 | | - async with client_async_local(cache_name, middleware_args) as client: |
69 | | - response = await client.get(cache_name, "key") |
70 | | - |
71 | | - assert isinstance(response, CacheGet.Miss) |
72 | | - |
73 | | - retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.GET) |
74 | | - assert 2 <= retry_count <= 3 |
| 12 | +@pytest.mark.asyncio |
| 13 | +@pytest.mark.local |
| 14 | +async def test_retry_eligible_api_should_make_max_attempts_when_full_network_outage() -> None: |
| 15 | + metrics_collector = MomentoLocalMetricsCollector() |
| 16 | + middleware_args = MomentoLocalMiddlewareArgs( |
| 17 | + request_id=str(uuid_str()), |
| 18 | + test_metrics_collector=metrics_collector, |
| 19 | + return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
| 20 | + error_rpc_list=[MomentoRpcMethod.GET], |
| 21 | + ) |
| 22 | + cache_name = uuid_str() |
| 23 | + |
| 24 | + async with client_async_local(cache_name, middleware_args) as client: |
| 25 | + response = await client.get(cache_name, "key") |
| 26 | + |
| 27 | + assert isinstance(response, CacheGet.Error) |
| 28 | + assert response.error_code == MomentoErrorCode.SERVER_UNAVAILABLE |
| 29 | + |
| 30 | + retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.GET) |
| 31 | + assert retry_count == 3 |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.asyncio |
| 35 | +@pytest.mark.local |
| 36 | +async def test_non_retry_eligible_api_should_make_no_attempts_when_full_network_outage() -> None: |
| 37 | + metrics_collector = MomentoLocalMetricsCollector() |
| 38 | + middleware_args = MomentoLocalMiddlewareArgs( |
| 39 | + request_id=str(uuid_str()), |
| 40 | + test_metrics_collector=metrics_collector, |
| 41 | + return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
| 42 | + error_rpc_list=[MomentoRpcMethod.INCREMENT], |
| 43 | + ) |
| 44 | + cache_name = uuid_str() |
| 45 | + |
| 46 | + async with client_async_local(cache_name, middleware_args) as client: |
| 47 | + response = await client.increment(cache_name, "key", 1) |
| 48 | + |
| 49 | + assert isinstance(response, CacheIncrement.Error) |
| 50 | + assert response.error_code == MomentoErrorCode.SERVER_UNAVAILABLE |
| 51 | + |
| 52 | + retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.INCREMENT) |
| 53 | + assert retry_count == 0 |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.asyncio |
| 57 | +@pytest.mark.local |
| 58 | +async def test_retry_eligible_api_should_make_less_than_max_attempts_when_temporary_network_outage() -> None: |
| 59 | + metrics_collector = MomentoLocalMetricsCollector() |
| 60 | + middleware_args = MomentoLocalMiddlewareArgs( |
| 61 | + request_id=str(uuid_str()), |
| 62 | + test_metrics_collector=metrics_collector, |
| 63 | + return_error=MomentoErrorCode.SERVER_UNAVAILABLE, |
| 64 | + error_rpc_list=[MomentoRpcMethod.GET], |
| 65 | + error_count=2, |
| 66 | + ) |
| 67 | + cache_name = uuid_str() |
| 68 | + |
| 69 | + async with client_async_local(cache_name, middleware_args) as client: |
| 70 | + response = await client.get(cache_name, "key") |
| 71 | + |
| 72 | + assert isinstance(response, CacheGet.Miss) |
| 73 | + |
| 74 | + retry_count = metrics_collector.get_total_retry_count(cache_name, MomentoRpcMethod.GET) |
| 75 | + assert 2 <= retry_count <= 3 |
0 commit comments