Abort execution of template renders that overwhelm the system (#40647)
This commit is contained in:
1 parent
8bc62f3678
commit
e08ee282ab
6 files changed
+212
-15
No files matched your search
@@ -397,9 +397,7 @@ async def test_subscribe_unsubscribe_events_state_changed(
|
||||
assert msg["event"]["data"]["entity_id"] == "light.permitted"
|
||||
|
||||
|
||||
async def test_render_template_renders_template(
|
||||
hass, websocket_client, hass_admin_user
|
||||
):
|
||||
async def test_render_template_renders_template(hass, websocket_client):
|
||||
"""Test simple template is rendered and updated."""
|
||||
hass.states.async_set("light.test", "on")
|
||||
|
||||
@@ -437,7 +435,7 @@ async def test_render_template_renders_template(
|
||||
|
||||
|
||||
async def test_render_template_manual_entity_ids_no_longer_needed(
|
||||
hass, websocket_client, hass_admin_user
|
||||
hass, websocket_client
|
||||
):
|
||||
"""Test that updates to specified entity ids cause a template rerender."""
|
||||
hass.states.async_set("light.test", "on")
|
||||
@@ -475,9 +473,7 @@ async def test_render_template_manual_entity_ids_no_longer_needed(
|
||||
}
|
||||
|
||||
|
||||
async def test_render_template_with_error(
|
||||
hass, websocket_client, hass_admin_user, caplog
|
||||
):
|
||||
async def test_render_template_with_error(hass, websocket_client, caplog):
|
||||
"""Test a template with an error."""
|
||||
await websocket_client.send_json(
|
||||
{"id": 5, "type": "render_template", "template": "{{ my_unknown_var() + 1 }}"}
|
||||
@@ -492,9 +488,7 @@ async def test_render_template_with_error(
|
||||
assert "TemplateError" not in caplog.text
|
||||
|
||||
|
||||
async def test_render_template_with_delayed_error(
|
||||
hass, websocket_client, hass_admin_user, caplog
|
||||
):
|
||||
async def test_render_template_with_delayed_error(hass, websocket_client, caplog):
|
||||
"""Test a template with an error that only happens after a state change."""
|
||||
hass.states.async_set("sensor.test", "on")
|
||||
await hass.async_block_till_done()
|
||||
@@ -539,9 +533,36 @@ async def test_render_template_with_delayed_error(
|
||||
assert "TemplateError" not in caplog.text
|
||||
|
||||
|
||||
async def test_render_template_returns_with_match_all(
|
||||
hass, websocket_client, hass_admin_user
|
||||
):
|
||||
async def test_render_template_with_timeout(hass, websocket_client, caplog):
|
||||
"""Test a template that will timeout."""
|
||||
|
||||
slow_template_str = """
|
||||
{% for var in range(1000) -%}
|
||||
{% for var in range(1000) -%}
|
||||
{{ var }}
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
"""
|
||||
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "render_template",
|
||||
"timeout": 0.000001,
|
||||
"template": slow_template_str,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["id"] == 5
|
||||
assert msg["type"] == const.TYPE_RESULT
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == const.ERR_TEMPLATE_ERROR
|
||||
|
||||
assert "TemplateError" not in caplog.text
|
||||
|
||||
|
||||
async def test_render_template_returns_with_match_all(hass, websocket_client):
|
||||
"""Test that a template that would match with all entities still return success."""
|
||||
await websocket_client.send_json(
|
||||
{"id": 5, "type": "render_template", "template": "State is: {{ 42 }}"}
|
||||
|
||||
Reference in new issue
Block a user