mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Test that homeassistant stop and restart do not block WS (#48081)
This commit is contained in:
parent
73e546e2b8
commit
40ce25800c
@ -1,5 +1,8 @@
|
|||||||
"""Tests for WebSocket API commands."""
|
"""Tests for WebSocket API commands."""
|
||||||
|
from unittest.mock import ANY, patch
|
||||||
|
|
||||||
from async_timeout import timeout
|
from async_timeout import timeout
|
||||||
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.websocket_api import const
|
from homeassistant.components.websocket_api import const
|
||||||
@ -47,6 +50,83 @@ async def test_call_service(hass, websocket_client):
|
|||||||
assert call.context.as_dict() == msg["result"]["context"]
|
assert call.context.as_dict() == msg["result"]["context"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("command", ("call_service", "call_service_action"))
|
||||||
|
async def test_call_service_blocking(hass, websocket_client, command):
|
||||||
|
"""Test call service commands block, except for homeassistant restart / stop."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.core.ServiceRegistry.async_call", autospec=True
|
||||||
|
) as mock_call:
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"type": "call_service",
|
||||||
|
"domain": "domain_test",
|
||||||
|
"service": "test_service",
|
||||||
|
"service_data": {"hello": "world"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
|
||||||
|
assert msg["id"] == 5
|
||||||
|
assert msg["type"] == const.TYPE_RESULT
|
||||||
|
assert msg["success"]
|
||||||
|
mock_call.assert_called_once_with(
|
||||||
|
ANY,
|
||||||
|
"domain_test",
|
||||||
|
"test_service",
|
||||||
|
{"hello": "world"},
|
||||||
|
blocking=True,
|
||||||
|
context=ANY,
|
||||||
|
target=ANY,
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.core.ServiceRegistry.async_call", autospec=True
|
||||||
|
) as mock_call:
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"type": "call_service",
|
||||||
|
"domain": "homeassistant",
|
||||||
|
"service": "test_service",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
|
||||||
|
assert msg["id"] == 6
|
||||||
|
assert msg["type"] == const.TYPE_RESULT
|
||||||
|
assert msg["success"]
|
||||||
|
mock_call.assert_called_once_with(
|
||||||
|
ANY,
|
||||||
|
"homeassistant",
|
||||||
|
"test_service",
|
||||||
|
ANY,
|
||||||
|
blocking=True,
|
||||||
|
context=ANY,
|
||||||
|
target=ANY,
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.core.ServiceRegistry.async_call", autospec=True
|
||||||
|
) as mock_call:
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"type": "call_service",
|
||||||
|
"domain": "homeassistant",
|
||||||
|
"service": "restart",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
|
||||||
|
assert msg["id"] == 7
|
||||||
|
assert msg["type"] == const.TYPE_RESULT
|
||||||
|
assert msg["success"]
|
||||||
|
mock_call.assert_called_once_with(
|
||||||
|
ANY, "homeassistant", "restart", ANY, blocking=False, context=ANY, target=ANY
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_call_service_target(hass, websocket_client):
|
async def test_call_service_target(hass, websocket_client):
|
||||||
"""Test call service command with target."""
|
"""Test call service command with target."""
|
||||||
calls = async_mock_service(hass, "domain_test", "test_service")
|
calls = async_mock_service(hass, "domain_test", "test_service")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user