From 1a760c63d0f8296f7151fcbd452d0909dbceb4cf Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Mon, 27 Jul 2020 03:43:58 -0500 Subject: [PATCH] Fix parallel script containing repeat or choose action with max_runs > 10 (#38243) --- homeassistant/helpers/script.py | 3 +++ tests/helpers/test_script.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index bc6e4bdbd36..cad0a272e47 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -809,6 +809,7 @@ class Script: action[CONF_REPEAT][CONF_SEQUENCE], f"{self.name}: {step_name}", script_mode=SCRIPT_MODE_PARALLEL, + max_runs=self.max_runs, logger=self._logger, top_level=False, ) @@ -836,6 +837,7 @@ class Script: choice[CONF_SEQUENCE], f"{self.name}: {step_name}: choice {idx}", script_mode=SCRIPT_MODE_PARALLEL, + max_runs=self.max_runs, logger=self._logger, top_level=False, ) @@ -850,6 +852,7 @@ class Script: action[CONF_DEFAULT], f"{self.name}: {step_name}: default", script_mode=SCRIPT_MODE_PARALLEL, + max_runs=self.max_runs, logger=self._logger, top_level=False, ) diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index ab30b0457c5..8b61a5db64b 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -1005,6 +1005,31 @@ async def test_choose(hass, var, result): assert events[0].data["choice"] == result +@pytest.mark.parametrize( + "action", + [ + {"repeat": {"count": 1, "sequence": {"event": "abc"}}}, + {"choose": {"conditions": [], "sequence": {"event": "abc"}}}, + {"choose": [], "default": {"event": "abc"}}, + ], +) +async def test_multiple_runs_repeat_choose(hass, caplog, action): + """Test parallel runs with repeat & choose actions & max_runs > default.""" + max_runs = script.DEFAULT_MAX + 1 + script_obj = script.Script( + hass, cv.SCRIPT_SCHEMA(action), script_mode="parallel", max_runs=max_runs + ) + + events = async_capture_events(hass, "abc") + for _ in range(max_runs): + hass.async_create_task(script_obj.async_run()) + await hass.async_block_till_done() + + assert "WARNING" not in caplog.text + assert "ERROR" not in caplog.text + assert len(events) == max_runs + + async def test_last_triggered(hass): """Test the last_triggered.""" event = "test_event"