mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Improve logging and handling when websocket gets behind (#86854)
fixes undefined
This commit is contained in:
@@ -21,37 +21,37 @@ from tests.common import MockUser
|
||||
exceptions.Unauthorized(),
|
||||
websocket_api.ERR_UNAUTHORIZED,
|
||||
"Unauthorized",
|
||||
"Error handling message: Unauthorized (unauthorized) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Unauthorized (unauthorized) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
vol.Invalid("Invalid something"),
|
||||
websocket_api.ERR_INVALID_FORMAT,
|
||||
"Invalid something. Got {'id': 5}",
|
||||
"Error handling message: Invalid something. Got {'id': 5} (invalid_format) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Invalid something. Got {'id': 5} (invalid_format) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
asyncio.TimeoutError(),
|
||||
websocket_api.ERR_TIMEOUT,
|
||||
"Timeout",
|
||||
"Error handling message: Timeout (timeout) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Timeout (timeout) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
exceptions.HomeAssistantError("Failed to do X"),
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
"Failed to do X",
|
||||
"Error handling message: Failed to do X (unknown_error) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Failed to do X (unknown_error) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
ValueError("Really bad"),
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
"Unknown error",
|
||||
"Error handling message: Unknown error (unknown_error) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Unknown error (unknown_error) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
exceptions.HomeAssistantError,
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
"Unknown error",
|
||||
"Error handling message: Unknown error (unknown_error) from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Unknown error (unknown_error) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -67,6 +67,50 @@ async def test_pending_msg_peak(hass, mock_low_peak, hass_ws_client, caplog):
|
||||
assert "Client unable to keep up with pending messages" in caplog.text
|
||||
|
||||
|
||||
async def test_pending_msg_peak_but_does_not_overflow(
|
||||
hass, mock_low_peak, hass_ws_client, caplog
|
||||
):
|
||||
"""Test pending msg hits the low peak but recovers and does not overflow."""
|
||||
orig_handler = http.WebSocketHandler
|
||||
instance: http.WebSocketHandler | None = None
|
||||
|
||||
def instantiate_handler(*args):
|
||||
nonlocal instance
|
||||
instance = orig_handler(*args)
|
||||
return instance
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.websocket_api.http.WebSocketHandler",
|
||||
instantiate_handler,
|
||||
):
|
||||
websocket_client = await hass_ws_client()
|
||||
|
||||
assert instance is not None
|
||||
|
||||
# Kill writer task and fill queue past peak
|
||||
for _ in range(5):
|
||||
instance._to_write.put_nowait(None)
|
||||
|
||||
# Trigger the peak check
|
||||
instance._send_message({})
|
||||
|
||||
# Clear the queue
|
||||
while instance._to_write.qsize() > 0:
|
||||
instance._to_write.get_nowait()
|
||||
|
||||
# Trigger the peak clear
|
||||
instance._send_message({})
|
||||
|
||||
async_fire_time_changed(
|
||||
hass, utcnow() + timedelta(seconds=const.PENDING_MSG_PEAK_TIME + 1)
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive()
|
||||
assert msg.type == WSMsgType.TEXT
|
||||
|
||||
assert "Client unable to keep up with pending messages" not in caplog.text
|
||||
|
||||
|
||||
async def test_non_json_message(hass, websocket_client, caplog):
|
||||
"""Test trying to serialize non JSON objects."""
|
||||
bad_data = object()
|
||||
|
||||
Reference in New Issue
Block a user