Fix flakey profiler object growth tests (#113825)

This commit is contained in:
J. Nick Koston 2024-03-19 09:17:12 -10:00 committed by GitHub
parent b35b4e8bfd
commit 15c0422837
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,7 @@ from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
from lru import LRU
import objgraph
import pytest
from homeassistant.components.profiler import (
@ -115,30 +116,31 @@ async def test_object_growth_logging(
assert hass.services.has_service(DOMAIN, SERVICE_START_LOG_OBJECTS)
assert hass.services.has_service(DOMAIN, SERVICE_STOP_LOG_OBJECTS)
with patch("objgraph.growth"):
with patch.object(objgraph, "growth"):
await hass.services.async_call(
DOMAIN, SERVICE_START_LOG_OBJECTS, {CONF_SCAN_INTERVAL: 10}, blocking=True
DOMAIN, SERVICE_START_LOG_OBJECTS, {CONF_SCAN_INTERVAL: 1}, blocking=True
)
with pytest.raises(HomeAssistantError, match="Object logging already started"):
await hass.services.async_call(
DOMAIN,
SERVICE_START_LOG_OBJECTS,
{CONF_SCAN_INTERVAL: 10},
{CONF_SCAN_INTERVAL: 1},
blocking=True,
)
assert "Growth" in caplog.text
await hass.async_block_till_done(wait_background_tasks=True)
caplog.clear()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=11))
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
await hass.async_block_till_done(wait_background_tasks=True)
assert "Growth" in caplog.text
await hass.services.async_call(DOMAIN, SERVICE_STOP_LOG_OBJECTS, {}, blocking=True)
caplog.clear()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=21))
await hass.async_block_till_done()
await hass.async_block_till_done(wait_background_tasks=True)
assert "Growth" not in caplog.text
with pytest.raises(HomeAssistantError, match="Object logging not running"):
@ -146,17 +148,18 @@ async def test_object_growth_logging(
DOMAIN, SERVICE_STOP_LOG_OBJECTS, {}, blocking=True
)
with patch("objgraph.growth"):
with patch.object(objgraph, "growth"):
await hass.services.async_call(
DOMAIN, SERVICE_START_LOG_OBJECTS, {CONF_SCAN_INTERVAL: 10}, blocking=True
)
await hass.async_block_till_done(wait_background_tasks=True)
caplog.clear()
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
await hass.async_block_till_done(wait_background_tasks=True)
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=31))
await hass.async_block_till_done()
await hass.async_block_till_done(wait_background_tasks=True)
assert "Growth" not in caplog.text