mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Better handle large amounts of data being sent over WS (#23842)
* Better handle large amounts of data being sent over WS * Lint
This commit is contained in:
30
tests/components/websocket_api/test_connection.py
Normal file
30
tests/components/websocket_api/test_connection.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Test WebSocket Connection class."""
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.websocket_api import const
|
||||
|
||||
|
||||
async def test_send_big_result(hass, websocket_client):
|
||||
"""Test sending big results over the WS."""
|
||||
@websocket_api.websocket_command({
|
||||
'type': 'big_result'
|
||||
})
|
||||
@websocket_api.async_response
|
||||
async def send_big_result(hass, connection, msg):
|
||||
await connection.send_big_result(
|
||||
msg['id'], {'big': 'result'}
|
||||
)
|
||||
|
||||
hass.components.websocket_api.async_register_command(
|
||||
send_big_result
|
||||
)
|
||||
|
||||
await websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': 'big_result',
|
||||
})
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == const.TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert msg['result'] == {'big': 'result'}
|
||||
Reference in New Issue
Block a user