Warn if start takes a long time. (#6975)
* Warn if start takes a long time. * ps - cleanup * Tweak message * Add tests * Tweak messagE
This commit is contained in:
parent
2277778d8d
commit
5d3fe83e62
2 changed files with 58 additions and 1 deletions
|
@ -5,6 +5,7 @@ import unittest
|
|||
from unittest.mock import patch, MagicMock, sentinel
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import logging
|
||||
import pytz
|
||||
import pytest
|
||||
|
||||
|
@ -867,3 +868,45 @@ def test_timer_out_of_sync(mock_monotonic, loop):
|
|||
assert slp_seconds == 1
|
||||
assert callback is fire_time_event
|
||||
assert abs(nxt - 12.3) < 0.001
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_hass_start_starts_the_timer(loop):
|
||||
"""Test when hass starts, it starts the timer."""
|
||||
hass = ha.HomeAssistant(loop=loop)
|
||||
|
||||
try:
|
||||
with patch('homeassistant.core._async_create_timer') as mock_timer:
|
||||
yield from hass.async_start()
|
||||
|
||||
assert hass.state == ha.CoreState.running
|
||||
assert not hass._track_task
|
||||
assert len(mock_timer.mock_calls) == 1
|
||||
assert mock_timer.mock_calls[0][1][0] is hass
|
||||
|
||||
finally:
|
||||
yield from hass.async_stop()
|
||||
assert hass.state == ha.CoreState.not_running
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_start_taking_too_long(loop, caplog):
|
||||
"""Test when async_start takes too long."""
|
||||
hass = ha.HomeAssistant(loop=loop)
|
||||
caplog.set_level(logging.WARNING)
|
||||
|
||||
try:
|
||||
with patch('homeassistant.core.timeout',
|
||||
side_effect=asyncio.TimeoutError), \
|
||||
patch('homeassistant.core._async_create_timer') as mock_timer:
|
||||
yield from hass.async_start()
|
||||
|
||||
assert not hass._track_task
|
||||
assert hass.state == ha.CoreState.running
|
||||
assert len(mock_timer.mock_calls) == 1
|
||||
assert mock_timer.mock_calls[0][1][0] is hass
|
||||
assert 'Something is blocking Home Assistant' in caplog.text
|
||||
|
||||
finally:
|
||||
yield from hass.async_stop()
|
||||
assert hass.state == ha.CoreState.not_running
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue