|
35 | 35 | ResponseError,
|
36 | 36 | )
|
37 | 37 | from redis.utils import str_if_bytes
|
| 38 | +from tests.test_asyncio.conftest import ( |
| 39 | + create_redis, |
| 40 | +) |
38 | 41 | from tests.conftest import (
|
39 | 42 | assert_resp_response,
|
40 | 43 | is_resp2_connection,
|
@@ -706,7 +709,7 @@ def cmd_init_mock(self, r: ClusterNode) -> None:
|
706 | 709 | (False, LoadBalancingStrategy.RANDOM_REPLICA, [7002, 7002, 7002]),
|
707 | 710 | ],
|
708 | 711 | )
|
709 |
| - async def test_reading_from_replicas_in_round_robin( |
| 712 | + async def test_reading_with_load_balancing_strategies( |
710 | 713 | self,
|
711 | 714 | read_from_replicas: bool,
|
712 | 715 | load_balancing_strategy: LoadBalancingStrategy,
|
@@ -1008,6 +1011,31 @@ async def test_get_and_set(self, r: RedisCluster) -> None:
|
1008 | 1011 | assert await r.get("integer") == str(integer).encode()
|
1009 | 1012 | assert (await r.get("unicode_string")).decode("utf-8") == unicode_string
|
1010 | 1013 |
|
| 1014 | + @pytest.mark.parametrize( |
| 1015 | + "load_balancing_strategy", |
| 1016 | + [ |
| 1017 | + LoadBalancingStrategy.ROUND_ROBIN, |
| 1018 | + LoadBalancingStrategy.ROUND_ROBIN_REPLICAS, |
| 1019 | + LoadBalancingStrategy.RANDOM_REPLICA, |
| 1020 | + ], |
| 1021 | + ) |
| 1022 | + async def test_get_and_set_with_load_balanced_client( |
| 1023 | + self, create_redis, load_balancing_strategy: LoadBalancingStrategy |
| 1024 | + ) -> None: |
| 1025 | + r = await create_redis(cls=RedisCluster, load_balancing_strategy=load_balancing_strategy) |
| 1026 | + |
| 1027 | + # get and set can't be tested independently of each other |
| 1028 | + assert await r.get("a") is None |
| 1029 | + |
| 1030 | + byte_string = b"value" |
| 1031 | + assert await r.set("byte_string", byte_string) |
| 1032 | + |
| 1033 | + # run the get command for the same key several times |
| 1034 | + # to iterate over the read nodes |
| 1035 | + assert await r.get("byte_string") == byte_string |
| 1036 | + assert await r.get("byte_string") == byte_string |
| 1037 | + assert await r.get("byte_string") == byte_string |
| 1038 | + |
1011 | 1039 | async def test_mget_nonatomic(self, r: RedisCluster) -> None:
|
1012 | 1040 | assert await r.mget_nonatomic([]) == []
|
1013 | 1041 | assert await r.mget_nonatomic(["a", "b"]) == [None, None]
|
|
0 commit comments