Paginate list responses when multi requests are disabled (#1838)
Some checks are pending
CI / Perform Lint Checks (3.15) (push) Waiting to run
CI / Python 3.11 on macos-latest (push) Blocked by required conditions
CI / Python 3.12 on macos-latest (push) Blocked by required conditions
CI / Python 3.13 on macos-latest (push) Blocked by required conditions
CI / Python 3.14 on macos-latest (push) Blocked by required conditions
CI / Python 3.15 on macos-latest (push) Blocked by required conditions
CI / Python 3.11 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.12 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.13 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.14 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.15 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.11 on windows-latest (push) Blocked by required conditions
CI / Python 3.12 on windows-latest (push) Blocked by required conditions
CI / Python 3.13 on windows-latest (push) Blocked by required conditions
CI / Python 3.14 on windows-latest (push) Blocked by required conditions
CI / Python 3.15 on windows-latest (push) Blocked by required conditions
CodeQL Checks / Analyze (python) (push) Waiting to run

Drop the separate `step == 1` send loop. With batching off, the requests
go through the existing loop at the end of the method, which now
paginates. That loop also handles lists requeried after an error in a
batch, which were truncated the same way with no timeout involved.

---------

Co-authored-by: ZeliardM <140266236+ZeliardM@users.noreply.github.com>
This commit is contained in:
DevilRange
2026-11-21 01:08:55 +02:00
committed by GitHub
parent 1b4e540ae6
commit 7a5b3a2658
2 changed files with 49 additions and 16 deletions

View File

@@ -494,8 +494,9 @@ async def test_smart_protocol_lists_single_request(
@pytest.mark.parametrize("list_sum", [5, 10, 30])
@pytest.mark.parametrize("batch_size", [1, 2, 3, 50])
@pytest.mark.parametrize("multi_request_batch_size", [5, 1])
async def test_smart_protocol_lists_multiple_request(
mocker: MockerFixture, list_sum: int, batch_size: int
mocker: MockerFixture, list_sum: int, batch_size: int, multi_request_batch_size: int
) -> None:
child_list = [{"foo": i} for i in range(list_sum)]
response = {
@@ -520,6 +521,7 @@ async def test_smart_protocol_lists_multiple_request(
get_child_fixtures=False,
)
protocol = SmartProtocol(transport=ft)
protocol._multi_request_batch_size = multi_request_batch_size
query_spy = mocker.spy(protocol, "_execute_query")
resp = await protocol.query(request)
expected_count = 1 + 2 * (
@@ -728,3 +730,39 @@ async def test_no_multiple_methods(
send_spy = mocker.spy(protocol._transport, "send")
await protocol.query(req)
assert send_spy.call_count == 2
async def test_smart_protocol_lists_requeried_after_batch_error() -> None:
"""Test that a list requeried after an error in its batch is complete."""
child_list = {
"child_device_list": [{"foo": i} for i in range(30)],
"start_index": 0,
"sum": 30,
}
ft = FakeSmartTransport(
{"get_child_device_list": child_list},
"foobar",
component_nego_not_included=True,
get_child_fixtures=False,
warn_fixture_missing_methods=False,
)
protocol = SmartProtocol(transport=ft)
resp = await protocol.query({"get_foo": None, "get_child_device_list": None})
assert resp["get_child_device_list"] == child_list
async def test_force_single_method_leaves_no_empty_batch(
dummy_protocol: SmartProtocol, mocker: MockerFixture
) -> None:
"""Test that a method sent on its own does not add an empty batch."""
dummy_protocol._multi_request_batch_size = 5
methods = [f"get_method_{i}" for i in range(5)]
responses = [{"method": m, "result": {}, "error_code": 0} for m in methods]
send_mock = mocker.patch.object(
dummy_protocol._transport,
"send",
return_value={"result": {"responses": responses}, "error_code": 0},
)
await dummy_protocol.query(dict.fromkeys([*methods, "scanApList"]), retry_count=0)
assert send_mock.call_count == 2