Speed up test teardown when no config entries are loaded (#117095)

Avoid the gather call when there are no loaded config entries
This commit is contained in:
J. Nick Koston 2024-05-09 09:14:07 -05:00 committed by GitHub
parent c1f0ebee2c
commit 333d5a9251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,7 +48,7 @@ from homeassistant.components.websocket_api.auth import (
) )
from homeassistant.components.websocket_api.http import URL from homeassistant.components.websocket_api.http import URL
from homeassistant.config import YAML_CONFIG_FILE from homeassistant.config import YAML_CONFIG_FILE
from homeassistant.config_entries import ConfigEntries, ConfigEntry from homeassistant.config_entries import ConfigEntries, ConfigEntry, ConfigEntryState
from homeassistant.const import HASSIO_USER_NAME from homeassistant.const import HASSIO_USER_NAME
from homeassistant.core import CoreState, HassJob, HomeAssistant from homeassistant.core import CoreState, HassJob, HomeAssistant
from homeassistant.helpers import ( from homeassistant.helpers import (
@ -558,10 +558,16 @@ async def hass(
# Config entries are not normally unloaded on HA shutdown. They are unloaded here # Config entries are not normally unloaded on HA shutdown. They are unloaded here
# to ensure that they could, and to help track lingering tasks and timers. # to ensure that they could, and to help track lingering tasks and timers.
loaded_entries = [
entry
for entry in hass.config_entries.async_entries()
if entry.state is ConfigEntryState.LOADED
]
if loaded_entries:
await asyncio.gather( await asyncio.gather(
*( *(
create_eager_task(config_entry.async_unload(hass)) create_eager_task(config_entry.async_unload(hass))
for config_entry in hass.config_entries.async_entries() for config_entry in loaded_entries
) )
) )