Handle prepare timeout in websocket API (#55989)

This commit is contained in:
Paulus Schoutsen 2021-10-08 22:12:06 -07:00 committed by GitHub
parent d55a7e5cc7
commit 6d0da631bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View file

@ -1,8 +1,9 @@
"""Test Websocket API http module."""
import asyncio
from datetime import timedelta
from unittest.mock import patch
from aiohttp import WSMsgType
from aiohttp import ServerDisconnectedError, WSMsgType, web
import pytest
from homeassistant.components.websocket_api import const, http
@ -80,3 +81,14 @@ async def test_non_json_message(hass, websocket_client, caplog):
f"Unable to serialize to JSON. Bad data found at $.result[0](State: test_domain.entity).attributes.bad={bad_data}(<class 'object'>"
in caplog.text
)
async def test_prepare_fail(hass, hass_ws_client, caplog):
"""Test failing to prepare."""
with patch(
"homeassistant.components.websocket_api.http.web.WebSocketResponse.prepare",
side_effect=(asyncio.TimeoutError, web.WebSocketResponse.prepare),
), pytest.raises(ServerDisconnectedError):
await hass_ws_client(hass)
assert "Timeout preparing request" in caplog.text