Log which task is blocking startup when debug logging is on (#38134)

* Log which task is blocking startup when debug logging for homeassistant.core is on

* test needs to go one level deeper now
This commit is contained in:
J. Nick Koston authored and Franck Nijhof committed 2020-07-24 21:53:55 +02:00
1 parent 24b8545ebe
commit 979dafd0a7
3 files changed
+39 -3

No files matched your search

+21
View File
@@ -1393,3 +1393,24 @@ async def test_start_events(hass):
EVENT_HOMEASSISTANT_STARTED,
]
assert core_states == [ha.CoreState.starting, ha.CoreState.running]
async def test_log_blocking_events(hass, caplog):
"""Ensure we log which task is blocking startup when debug logging is on."""
caplog.set_level(logging.DEBUG)
async def _wait_a_bit_1():
await asyncio.sleep(0.1)
async def _wait_a_bit_2():
await asyncio.sleep(0.1)
hass.async_create_task(_wait_a_bit_1())
await hass.async_block_till_done()
with patch.object(ha, "BLOCK_LOG_TIMEOUT", 0.00001):
hass.async_create_task(_wait_a_bit_2())
await hass.async_block_till_done()
assert "_wait_a_bit_2" in caplog.text
assert "_wait_a_bit_1" not in caplog.text