Speedup tests command_line integration (#96349)

This commit is contained in:
Jan Bouwhuis 2023-07-11 18:31:32 +02:00 committed by GitHub
parent 49b6c8ed6e
commit 50442c5688
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 45 deletions

View file

@ -293,16 +293,19 @@ async def test_updating_to_often(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test handling updating when command already running."""
called = []
wait_till_event = asyncio.Event()
wait_till_event.set()
class MockCommandCover(CommandCover):
"""Mock entity that updates slow."""
"""Mock entity that updates."""
async def _async_update(self) -> None:
"""Update slow."""
"""Update the entity."""
called.append(1)
# Add waiting time
await asyncio.sleep(1)
await wait_till_event.wait()
with patch(
"homeassistant.components.command_line.cover.CommandCover",
@ -318,7 +321,7 @@ async def test_updating_to_often(
"command_state": "echo 1",
"value_template": "{{ value }}",
"name": "Test",
"scan_interval": 0.1,
"scan_interval": 10,
}
}
]
@ -331,20 +334,31 @@ async def test_updating_to_often(
"Updating Command Line Cover Test took longer than the scheduled update interval"
not in caplog.text
)
called.clear()
caplog.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1))
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=11))
await hass.async_block_till_done()
assert called
called.clear()
assert (
"Updating Command Line Cover Test took longer than the scheduled update interval"
not in caplog.text
)
# Simulate update takes too long
wait_till_event.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10))
await asyncio.sleep(0)
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10))
wait_till_event.set()
# Finish processing update
await hass.async_block_till_done()
assert called
assert (
"Updating Command Line Cover Test took longer than the scheduled update interval"
in caplog.text
)
await asyncio.sleep(0.2)
async def test_updating_manually(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture