Log unhandled loop exception traces when asyncio debug is on (#57602)

This commit is contained in:
J. Nick Koston 2021-10-18 17:07:51 -10:00 committed by GitHub
parent f92fe38bbd
commit 6576225c48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View file

@ -117,3 +117,23 @@ def test_run_does_not_block_forever_with_shielded_task(hass, tmpdir, caplog):
assert (
"Task could not be canceled and was still running after shutdown" in caplog.text
)
async def test_unhandled_exception_traceback(hass, caplog):
"""Test an unhandled exception gets a traceback in debug mode."""
async def _unhandled_exception():
raise Exception("This is unhandled")
try:
hass.loop.set_debug(True)
asyncio.create_task(_unhandled_exception())
finally:
hass.loop.set_debug(False)
await asyncio.sleep(0)
await asyncio.sleep(0)
assert "Task exception was never retrieved" in caplog.text
assert "This is unhandled" in caplog.text
assert "_unhandled_exception" in caplog.text