Bugfix wait on start event (#7013)
* Bugfix wait on start event * Paulus sugestion * Change handling with stop_track_task * Add new unittests * Update test_core.py
This commit is contained in:
parent
cc459e25cc
commit
b52cabf2c0
3 changed files with 22 additions and 10 deletions
|
@ -164,15 +164,16 @@ class HomeAssistant(object):
|
||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# only block for EVENT_HOMEASSISTANT_START listener
|
||||||
|
self.async_stop_track_tasks()
|
||||||
with timeout(TIMEOUT_EVENT_START, loop=self.loop):
|
with timeout(TIMEOUT_EVENT_START, loop=self.loop):
|
||||||
yield from self.async_stop_track_tasks()
|
yield from self.async_block_till_done()
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
'Something is blocking Home Assistant from wrapping up the '
|
'Something is blocking Home Assistant from wrapping up the '
|
||||||
'start up phase. We\'re going to continue anyway. Please '
|
'start up phase. We\'re going to continue anyway. Please '
|
||||||
'report the following info at http://bit.ly/2ogP58T : %s',
|
'report the following info at http://bit.ly/2ogP58T : %s',
|
||||||
', '.join(self.config.components))
|
', '.join(self.config.components))
|
||||||
self._track_task = False
|
|
||||||
|
|
||||||
self.state = CoreState.running
|
self.state = CoreState.running
|
||||||
_async_create_timer(self)
|
_async_create_timer(self)
|
||||||
|
@ -218,10 +219,9 @@ class HomeAssistant(object):
|
||||||
"""Track tasks so you can wait for all tasks to be done."""
|
"""Track tasks so you can wait for all tasks to be done."""
|
||||||
self._track_task = True
|
self._track_task = True
|
||||||
|
|
||||||
@asyncio.coroutine
|
@callback
|
||||||
def async_stop_track_tasks(self):
|
def async_stop_track_tasks(self):
|
||||||
"""Track tasks so you can wait for all tasks to be done."""
|
"""Stop track tasks so you can't wait for all tasks to be done."""
|
||||||
yield from self.async_block_till_done()
|
|
||||||
self._track_task = False
|
self._track_task = False
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -246,8 +246,6 @@ class HomeAssistant(object):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_block_till_done(self):
|
def async_block_till_done(self):
|
||||||
"""Block till all pending work is done."""
|
"""Block till all pending work is done."""
|
||||||
assert self._track_task, 'Not tracking tasks'
|
|
||||||
|
|
||||||
# To flush out any call_soon_threadsafe
|
# To flush out any call_soon_threadsafe
|
||||||
yield from asyncio.sleep(0, loop=self.loop)
|
yield from asyncio.sleep(0, loop=self.loop)
|
||||||
|
|
||||||
|
|
|
@ -122,8 +122,7 @@ def async_test_home_assistant(loop):
|
||||||
# 1. We only mock time during tests
|
# 1. We only mock time during tests
|
||||||
# 2. We want block_till_done that is called inside stop_track_tasks
|
# 2. We want block_till_done that is called inside stop_track_tasks
|
||||||
with patch('homeassistant.core._async_create_timer'), \
|
with patch('homeassistant.core._async_create_timer'), \
|
||||||
patch.object(hass, 'async_stop_track_tasks',
|
patch.object(hass, 'async_stop_track_tasks'):
|
||||||
hass.async_block_till_done):
|
|
||||||
yield from orig_start()
|
yield from orig_start()
|
||||||
|
|
||||||
hass.async_start = mock_async_start
|
hass.async_start = mock_async_start
|
||||||
|
|
|
@ -901,7 +901,6 @@ def test_start_taking_too_long(loop, caplog):
|
||||||
patch('homeassistant.core._async_create_timer') as mock_timer:
|
patch('homeassistant.core._async_create_timer') as mock_timer:
|
||||||
yield from hass.async_start()
|
yield from hass.async_start()
|
||||||
|
|
||||||
assert not hass._track_task
|
|
||||||
assert hass.state == ha.CoreState.running
|
assert hass.state == ha.CoreState.running
|
||||||
assert len(mock_timer.mock_calls) == 1
|
assert len(mock_timer.mock_calls) == 1
|
||||||
assert mock_timer.mock_calls[0][1][0] is hass
|
assert mock_timer.mock_calls[0][1][0] is hass
|
||||||
|
@ -910,3 +909,19 @@ def test_start_taking_too_long(loop, caplog):
|
||||||
finally:
|
finally:
|
||||||
yield from hass.async_stop()
|
yield from hass.async_stop()
|
||||||
assert hass.state == ha.CoreState.not_running
|
assert hass.state == ha.CoreState.not_running
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_track_task_functions(loop):
|
||||||
|
"""Test function to start/stop track task and initial state."""
|
||||||
|
hass = ha.HomeAssistant(loop=loop)
|
||||||
|
try:
|
||||||
|
assert hass._track_task
|
||||||
|
|
||||||
|
hass.async_stop_track_tasks()
|
||||||
|
assert not hass._track_task
|
||||||
|
|
||||||
|
hass.async_track_tasks()
|
||||||
|
assert hass._track_task
|
||||||
|
finally:
|
||||||
|
yield from hass.async_stop()
|
||||||
|
|
Loading…
Add table
Reference in a new issue