[+!] all but small

some small modifications, tests added
This commit is contained in:
2026-10-07 22:42:46 +03:00
parent fac12b2ea8
commit c16ed7915a
21 changed files with 1190 additions and 100 deletions

View File

@@ -227,13 +227,50 @@ def test_handshake_retry_limit_requests_disconnect(make_session, timing):
run(scenario)
def test_stopped_session_does_not_send_packets(make_session, timing):
"""Проверяет, что после stop новые отправки не поступают закрытому соединению."""
@pytest.mark.parametrize("state", ["stop", "migrated"])
def test_stopped_session_does_not_send_packets(make_session, timing, state):
"""Проверяет запрет новых отправок в stop и migrated."""
async def scenario():
async with timing:
case = make_session()
await case.session.stop()
case.session.state = state
case.session.send({"command": "telemetry", "payload": {}})
await asyncio.sleep(0)
assert case.connection.sent == []
run(scenario)
def test_background_send_does_not_block_processing_data(make_session, timing, monkeypatch):
"""Проверяет обработку новых данных, пока фоновая сетевая отправка ожидает завершения."""
async def scenario():
async with timing:
case = make_session()
case.session.state = "air"
started, release, finished = asyncio.Event(), asyncio.Event(), asyncio.Event()
original_send = case.connection.send
async def pending_send(packet):
started.set()
try:
await release.wait()
await original_send(packet)
finally:
finished.set()
monkeypatch.setattr(case.connection, "send", pending_send)
packet = {"command": "telemetry", "payload": {"battery": 87}}
try:
case.session.send(packet)
await asyncio.wait_for(started.wait(), 1)
assert case.connection.sent == []
event = await asyncio.wait_for(case.session.feed({
"command": "status", "payload": {"ready": True},
}), 1)
assert event == {"type": "data", "data": "status"}
assert case.session.last_data == {"status": {"ready": True}}
finally:
release.set()
await asyncio.wait_for(finished.wait(), 1)
assert case.connection.sent == [packet]
run(scenario)