Add a 60s timeout to shell_command to prevent processes from building up (#38491)
If a process never ended, there was not timeout and they would build up in the background until Home Assistant crashed.
This commit is contained in:
parent
c33f309d5f
commit
dddcb8e299
2 changed files with 39 additions and 2 deletions
|
@ -6,7 +6,7 @@ from typing import Tuple
|
|||
import unittest
|
||||
|
||||
from homeassistant.components import shell_command
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component, setup_component
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
@ -178,3 +178,23 @@ class TestShellCommand(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
assert mock_output.call_count == 1
|
||||
assert test_phrase.encode() + b"\n" == mock_output.call_args_list[0][0][-1]
|
||||
|
||||
|
||||
async def test_do_no_run_forever(hass, caplog):
|
||||
"""Test subprocesses terminate after the timeout."""
|
||||
|
||||
with patch.object(shell_command, "COMMAND_TIMEOUT", 0.001):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
shell_command.DOMAIN,
|
||||
{shell_command.DOMAIN: {"test_service": "sleep 10000"}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
shell_command.DOMAIN, "test_service", blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "Timed out" in caplog.text
|
||||
assert "sleep 10000" in caplog.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue