Prevent integrations from retrying setup once shutdown has started (#88818)
* Prevent integrations from retrying setup once shutdown has started * coverage
This commit is contained in:
parent
4898d22960
commit
f8934175cb
2 changed files with 26 additions and 0 deletions
|
@ -445,6 +445,10 @@ class ConfigEntry:
|
|||
|
||||
async def setup_again(*_: Any) -> None:
|
||||
"""Run setup again."""
|
||||
# Check again when we fire in case shutdown
|
||||
# has started so we do not block shutdown
|
||||
if hass.is_stopping:
|
||||
return
|
||||
self._async_cancel_retry_setup = None
|
||||
await self.async_setup(hass, integration=integration, tries=tries)
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.helpers import entity_registry as er
|
|||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
from homeassistant.setup import async_set_domains_to_be_loaded, async_setup_component
|
||||
from homeassistant.util import dt
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .common import (
|
||||
MockConfigEntry,
|
||||
|
@ -999,6 +1000,27 @@ async def test_setup_retrying_during_unload_before_started(hass: HomeAssistant)
|
|||
)
|
||||
|
||||
|
||||
async def test_setup_does_not_retry_during_shutdown(hass: HomeAssistant) -> None:
|
||||
"""Test we do not retry when HASS is shutting down."""
|
||||
entry = MockConfigEntry(domain="test")
|
||||
|
||||
mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady)
|
||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
await entry.async_setup(hass)
|
||||
|
||||
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
hass.state = CoreState.stopping
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_create_entry_options(hass: HomeAssistant) -> None:
|
||||
"""Test a config entry being created with options."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue