Skip to content

Commit 7842b36

Browse files
committed
make local tests module-based instead of class-based
1 parent ee0f09d commit 7842b36

2 files changed

Lines changed: 125 additions & 123 deletions

File tree

tests/momento/local/test_fixed_count_retry_strategy.py

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,64 @@
99
from tests.utils import uuid_str
1010

1111

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

tests/momento/local/test_fixed_count_retry_strategy_async.py

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,67 @@
99
from tests.utils import uuid_str
1010

1111

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

Comments
 (0)