Fix thundering heard in setup_again when there are many integrations (#84670)

This commit is contained in:
J. Nick Koston 2022-12-27 15:59:42 -10:00 committed by GitHub
parent cc27986cac
commit 4296f227cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from copy import deepcopy
from enum import Enum
import functools
import logging
from random import randint
from types import MappingProxyType, MethodType
from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast
import weakref
@ -27,7 +28,11 @@ from .exceptions import (
)
from .helpers import device_registry, entity_registry, storage
from .helpers.dispatcher import async_dispatcher_send
from .helpers.event import async_call_later
from .helpers.event import (
RANDOM_MICROSECOND_MAX,
RANDOM_MICROSECOND_MIN,
async_call_later,
)
from .helpers.frame import report
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
from .setup import DATA_SETUP_DONE, async_process_deps_reqs, async_setup_component
@ -409,7 +414,9 @@ class ConfigEntry:
result = False
except ConfigEntryNotReady as ex:
self.async_set_state(hass, ConfigEntryState.SETUP_RETRY, str(ex) or None)
wait_time = 2 ** min(tries, 4) * 5
wait_time = 2 ** min(tries, 4) * 5 + (
randint(RANDOM_MICROSECOND_MIN, RANDOM_MICROSECOND_MAX) / 1000000
)
tries += 1
message = str(ex)
ready_message = f"ready yet: {message}" if message else "ready yet"

View File

@ -903,7 +903,7 @@ async def test_setup_raise_not_ready(hass, caplog):
p_hass, p_wait_time, p_setup = mock_call.mock_calls[0][1]
assert p_hass is hass
assert p_wait_time == 5
assert 5 <= p_wait_time <= 5.5
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY
assert entry.reason == "The internet connection is offline"