Move thread safety check in async_register/async_remove (#116077)

This commit is contained in:
J. Nick Koston 2024-04-24 10:41:11 +02:00 committed by GitHub
parent 5bded2a52d
commit e0b58c3f45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 63 additions and 4 deletions

View file

@ -3457,3 +3457,26 @@ async def test_async_fire_thread_safety(hass: HomeAssistant) -> None:
await hass.async_add_executor_job(hass.bus.async_fire, "test_event")
assert len(events) == 1
async def test_async_register_thread_safety(hass: HomeAssistant) -> None:
"""Test async_register thread safety."""
with pytest.raises(
RuntimeError, match="Detected code that calls async_register from a thread."
):
await hass.async_add_executor_job(
hass.services.async_register,
"test_domain",
"test_service",
lambda call: None,
)
async def test_async_remove_thread_safety(hass: HomeAssistant) -> None:
"""Test async_remove thread safety."""
with pytest.raises(
RuntimeError, match="Detected code that calls async_remove from a thread."
):
await hass.async_add_executor_job(
hass.services.async_remove, "test_domain", "test_service"
)