|
6 | 6 | from typing import List, Optional, Union, cast |
7 | 7 |
|
8 | 8 | import pytest |
| 9 | +from glide import RequestError, TimeoutError |
9 | 10 | from glide.async_commands.batch import ( |
10 | 11 | BaseBatch, |
11 | 12 | Batch, |
|
30 | 31 | ExpiryTypeGetEx, |
31 | 32 | FlushMode, |
32 | 33 | FunctionRestorePolicy, |
| 34 | + InfoSection, |
33 | 35 | InsertPosition, |
34 | 36 | ) |
35 | 37 | from glide.async_commands.sorted_set import ( |
|
57 | 59 | from glide.config import ProtocolVersion |
58 | 60 | from glide.constants import OK, TResult, TSingleNodeRoute |
59 | 61 | from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient |
60 | | -from glide.routes import SlotIdRoute, SlotType |
| 62 | +from glide.routes import AllNodes, SlotIdRoute, SlotKeyRoute, SlotType |
61 | 63 |
|
62 | | -from glide import RequestError, TimeoutError |
63 | 64 | from tests.conftest import create_client |
64 | 65 | from tests.utils.utils import ( |
65 | 66 | check_if_server_version_lt, |
@@ -1604,3 +1605,46 @@ async def test_batch_raise_on_error( |
1604 | 1605 | await exec_batch(glide_client, batch, raise_on_error=True) |
1605 | 1606 |
|
1606 | 1607 | 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