mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 05:20:17 +00:00
Speed up logger setup (#114610)
* Speed up logger setup Preload core.logger and avoid saving it until after startup * add comment about 180s * Adjust grammar --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""The tests for the Logger component."""
|
||||
|
||||
from collections import defaultdict
|
||||
import datetime
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
@@ -9,8 +10,12 @@ import pytest
|
||||
|
||||
from homeassistant.components import logger
|
||||
from homeassistant.components.logger import LOGSEVERITY
|
||||
from homeassistant.components.logger.helpers import SAVE_DELAY_LONG
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
HASS_NS = "unused.homeassistant"
|
||||
COMPONENTS_NS = f"{HASS_NS}.components"
|
||||
@@ -403,7 +408,7 @@ async def test_log_once_removed_from_store(
|
||||
hass: HomeAssistant, hass_storage: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test logs with persistence "once" are removed from the store at startup."""
|
||||
hass_storage["core.logger"] = {
|
||||
store_contents = {
|
||||
"data": {
|
||||
"logs": {
|
||||
ZONE_NS: {"type": "module", "level": "DEBUG", "persistence": "once"}
|
||||
@@ -412,7 +417,15 @@ async def test_log_once_removed_from_store(
|
||||
"key": "core.logger",
|
||||
"version": 1,
|
||||
}
|
||||
hass_storage["core.logger"] = store_contents
|
||||
|
||||
assert await async_setup_component(hass, "logger", {})
|
||||
|
||||
assert hass_storage["core.logger"]["data"] == store_contents["data"]
|
||||
|
||||
async_fire_time_changed(
|
||||
hass, dt_util.utcnow() + datetime.timedelta(seconds=SAVE_DELAY_LONG)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass_storage["core.logger"]["data"] == {"logs": {}}
|
||||
|
||||
Reference in New Issue
Block a user