Skip to content

Commit 32b400d

Browse files
committed
fix imports and add route test
Signed-off-by: BoazBD <boaz@bardavid.com>
1 parent 0b22804 commit 32b400d

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

python/tests/test_async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Dict, List, Mapping, Optional, Union, cast
1111

1212
import pytest
13+
from glide import ClosingError, RequestError, Script
1314
from glide.async_commands.batch import Batch, ClusterBatch
1415
from glide.async_commands.bitmap import (
1516
BitFieldGet,
@@ -83,7 +84,6 @@
8384
SlotType,
8485
)
8586

86-
from glide import ClosingError, RequestError, Script
8787
from tests.conftest import create_client
8888
from tests.utils.utils import (
8989
check_function_list_response,

python/tests/test_batch.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import List, Optional, Union, cast
77

88
import pytest
9+
from glide import RequestError, TimeoutError
910
from glide.async_commands.batch import (
1011
BaseBatch,
1112
Batch,
@@ -30,6 +31,7 @@
3031
ExpiryTypeGetEx,
3132
FlushMode,
3233
FunctionRestorePolicy,
34+
InfoSection,
3335
InsertPosition,
3436
)
3537
from glide.async_commands.sorted_set import (
@@ -57,9 +59,8 @@
5759
from glide.config import ProtocolVersion
5860
from glide.constants import OK, TResult, TSingleNodeRoute
5961
from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient
60-
from glide.routes import SlotIdRoute, SlotType
62+
from glide.routes import AllNodes, SlotIdRoute, SlotKeyRoute, SlotType
6163

62-
from glide import RequestError, TimeoutError
6364
from tests.conftest import create_client
6465
from tests.utils.utils import (
6566
check_if_server_version_lt,
@@ -1604,3 +1605,46 @@ async def test_batch_raise_on_error(
16041605
await exec_batch(glide_client, batch, raise_on_error=True)
16051606

16061607
assert "WRONGTYPE" in str(e.value)
1608+
1609+
@pytest.mark.parametrize("cluster_mode", [True])
1610+
@pytest.mark.parametrize("is_atomic", [True, False])
1611+
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
1612+
async def test_cluster_batch_route(
1613+
self,
1614+
glide_client: GlideClusterClient,
1615+
protocol: ProtocolVersion,
1616+
is_atomic: bool,
1617+
):
1618+
if await check_if_server_version_lt(glide_client, "6.0.0"):
1619+
pytest.skip("CONFIG RESETSTAT requires redis >= 6.0")
1620+
1621+
assert await glide_client.config_resetstat() == OK
1622+
1623+
key = get_random_string(10)
1624+
value = "value"
1625+
value_bytes = value.encode()
1626+
1627+
batch = ClusterBatch(is_atomic=is_atomic)
1628+
batch.set(key, value)
1629+
batch.get(key)
1630+
1631+
route = SlotKeyRoute(slot_type=SlotType.PRIMARY, slot_key=key)
1632+
results = await glide_client.exec(
1633+
batch, raise_on_error=True, route=route, timeout=2000
1634+
)
1635+
1636+
assert results == [OK, value_bytes]
1637+
1638+
# Check that no MOVED error occurred by inspecting errorstats on all nodes
1639+
error_stats_dict = await glide_client.info(
1640+
sections=[InfoSection.ERROR_STATS], route=AllNodes()
1641+
)
1642+
assert isinstance(error_stats_dict, dict)
1643+
1644+
for node_address, node_info in error_stats_dict.items():
1645+
assert isinstance(node_info, bytes)
1646+
# Ensure the errorstats section indicates no errors reported for this test
1647+
# It should only contain the header line.
1648+
assert (
1649+
node_info.strip() == b"# Errorstats"
1650+
), f"Node {node_address} reported errors: {node_info.decode()}"

0 commit comments

Comments
 (0)