Skip to content

Commit

Permalink
upload timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Adar Ovadia <[email protected]>
  • Loading branch information
Adar Ovadia committed Nov 20, 2024
1 parent 8a14359 commit 41bfc6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
104 changes: 51 additions & 53 deletions python/python/tests/test_read_from_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,38 @@ 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,
addresses=multiple_replicas_cluster.nodes_addr,
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,
Expand All @@ -62,77 +72,56 @@ 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,
addresses=multiple_replicas_cluster.nodes_addr,
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(
Expand All @@ -144,29 +133,38 @@ 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_testing_az.close()

Expand Down
2 changes: 1 addition & 1 deletion python/python/tests/utils/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41bfc6a

Please sign in to comment.