From a2cb6f86b38cc010fab9565c4e8df783230bc706 Mon Sep 17 00:00:00 2001 From: Adar Ovadia Date: Wed, 20 Nov 2024 15:55:49 +0000 Subject: [PATCH] upload timeout Signed-off-by: Adar Ovadia --- .../python/tests/test_read_from_strategy.py | 104 +++++++++--------- python/python/tests/utils/cluster.py | 2 +- 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/python/python/tests/test_read_from_strategy.py b/python/python/tests/test_read_from_strategy.py index fc15481a070..37249dc7ab4 100644 --- a/python/python/tests/test_read_from_strategy.py +++ b/python/python/tests/test_read_from_strategy.py @@ -30,16 +30,18 @@ async def _get_num_replicas(self, client: GlideClusterClient) -> int: @pytest.mark.skip_if_version_below("8.0.0") @pytest.mark.parametrize("cluster_mode", [True]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) - async def test_routing_by_slot_to_replica_with_az_affinity_strategy_to_all_replicas( + async def test_routing_with_az_affinity_strategy_to_1_replica( self, request, cluster_mode: bool, protocol: ProtocolVersion, multiple_replicas_cluster, ): - """Test that the client with AZ affinity strategy routes in a round-robin manner to all replicas within the specified AZ""" - + """Test that the client with az affinity strategy will only route to the 1 replica with the same az""" az = "us-east-1a" + GET_CALLS = 3 + get_cmdstat = f"cmdstat_get:calls={GET_CALLS}" + client_for_config_set = await create_client( request, cluster_mode, @@ -47,11 +49,19 @@ async def test_routing_by_slot_to_replica_with_az_affinity_strategy_to_all_repli protocol=protocol, timeout=2000, ) + + # Reset the availability zone for all nodes + await client_for_config_set.custom_command( + ["CONFIG", "SET", "availability-zone", ""], + route=AllNodes(), + ) await client_for_config_set.config_resetstat() == OK + + # 12182 is the slot of "foo" await client_for_config_set.custom_command( - ["CONFIG", "SET", "availability-zone", az], AllNodes() + ["CONFIG", "SET", "availability-zone", az], + route=SlotIdRoute(SlotType.REPLICA, 12182), ) - await client_for_config_set.close() client_for_testing_az = await create_client( request, @@ -62,56 +72,45 @@ async def test_routing_by_slot_to_replica_with_az_affinity_strategy_to_all_repli timeout=2000, client_az=az, ) - azs = await client_for_testing_az.custom_command( - ["CONFIG", "GET", "availability-zone"], AllNodes() - ) - - # Check that all replicas have the availability zone set to the az - assert all( - ( - node[1].decode() == az - if isinstance(node, list) - else node[b"availability-zone"].decode() == az - ) - for node in azs.values() - ) - - n_replicas = await self._get_num_replicas(client_for_testing_az) - GET_CALLS = 3 * n_replicas - get_cmdstat = f"cmdstat_get:calls={GET_CALLS // n_replicas}" for _ in range(GET_CALLS): await client_for_testing_az.get("foo") info_result = await client_for_testing_az.info( - [InfoSection.COMMAND_STATS, InfoSection.SERVER], AllNodes() + [InfoSection.SERVER, InfoSection.COMMAND_STATS], AllNodes() ) - # Check that all replicas have the same number of GET calls + # Check that only the replica with az has all the GET calls matching_entries_count = sum( 1 for value in info_result.values() if get_cmdstat in value.decode() and az in value.decode() ) - assert matching_entries_count == n_replicas + assert matching_entries_count == 1 + # Check that the other replicas have no availability zone set + changed_az_count = sum( + 1 + for node in info_result.values() + if f"availability_zone:{az}" in node.decode() + ) + assert changed_az_count == 1 await client_for_testing_az.close() + await client_for_config_set.close() @pytest.mark.skip_if_version_below("8.0.0") @pytest.mark.parametrize("cluster_mode", [True]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) - async def test_routing_with_az_affinity_strategy_to_1_replica( + async def test_routing_by_slot_to_replica_with_az_affinity_strategy_to_all_replicas( self, request, cluster_mode: bool, protocol: ProtocolVersion, multiple_replicas_cluster, ): - """Test that the client with az affinity strategy will only route to the 1 replica with the same az""" - az = "us-east-1a" - GET_CALLS = 3 - get_cmdstat = f"cmdstat_get:calls={GET_CALLS}" + """Test that the client with AZ affinity strategy routes in a round-robin manner to all replicas within the specified AZ""" + az = "us-east-1a" client_for_config_set = await create_client( request, cluster_mode, @@ -119,22 +118,11 @@ async def test_routing_with_az_affinity_strategy_to_1_replica( protocol=protocol, timeout=2000, ) - - # Reset the availability zone for all nodes - await client_for_config_set.custom_command( - ["CONFIG", "SET", "availability-zone", ""], - route=AllNodes(), - ) await client_for_config_set.config_resetstat() == OK - - # 12182 is the slot of "foo" await client_for_config_set.custom_command( - ["CONFIG", "SET", "availability-zone", az], - route=SlotIdRoute(SlotType.REPLICA, 12182), + ["CONFIG", "SET", "availability-zone", az], AllNodes() ) - await client_for_config_set.close() - client_for_testing_az = await create_client( request, cluster_mode, @@ -144,30 +132,40 @@ async def test_routing_with_az_affinity_strategy_to_1_replica( timeout=2000, client_az=az, ) + azs = await client_for_testing_az.custom_command( + ["CONFIG", "GET", "availability-zone"], AllNodes() + ) + + # Check that all replicas have the availability zone set to the az + assert all( + ( + node[1].decode() == az + if isinstance(node, list) + else node[b"availability-zone"].decode() == az + ) + for node in azs.values() + ) + + n_replicas = await self._get_num_replicas(client_for_testing_az) + GET_CALLS = 3 * n_replicas + get_cmdstat = f"cmdstat_get:calls={GET_CALLS // n_replicas}" for _ in range(GET_CALLS): await client_for_testing_az.get("foo") info_result = await client_for_testing_az.info( - [InfoSection.SERVER, InfoSection.COMMAND_STATS], AllNodes() + [InfoSection.COMMAND_STATS, InfoSection.SERVER], AllNodes() ) - # Check that only the replica with az has all the GET calls + # Check that all replicas have the same number of GET calls matching_entries_count = sum( 1 for value in info_result.values() if get_cmdstat in value.decode() and az in value.decode() ) - assert matching_entries_count == 1 - - # Check that the other replicas have no availability zone set - changed_az_count = sum( - 1 - for node in info_result.values() - if f"availability_zone:{az}" in node.decode() - ) - assert changed_az_count == 1 + assert matching_entries_count == n_replicas + await client_for_config_set.close() await client_for_testing_az.close() @pytest.mark.skip_if_version_below("8.0.0") diff --git a/python/python/tests/utils/cluster.py b/python/python/tests/utils/cluster.py index e0bfb231ae2..fa17742e7bb 100644 --- a/python/python/tests/utils/cluster.py +++ b/python/python/tests/utils/cluster.py @@ -45,7 +45,7 @@ def __init__( stderr=subprocess.PIPE, text=True, ) - output, err = p.communicate(timeout=40) + output, err = p.communicate(timeout=80) if p.returncode != 0: raise Exception(f"Failed to create a cluster. Executed: {p}:\n{err}") self.parse_cluster_script_start_output(output)