mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix bug in timeout util related to multiple global freezes (#122466)
This commit is contained in:
parent
5f08883227
commit
9b497aebb4
@ -61,18 +61,16 @@ class _GlobalFreezeContext:
|
||||
|
||||
def _enter(self) -> None:
|
||||
"""Run freeze."""
|
||||
if not self._manager.freezes_done:
|
||||
return
|
||||
if self._manager.freezes_done:
|
||||
# Global reset
|
||||
for task in self._manager.global_tasks:
|
||||
task.pause()
|
||||
|
||||
# Global reset
|
||||
for task in self._manager.global_tasks:
|
||||
task.pause()
|
||||
|
||||
# Zones reset
|
||||
for zone in self._manager.zones.values():
|
||||
if not zone.freezes_done:
|
||||
continue
|
||||
zone.pause()
|
||||
# Zones reset
|
||||
for zone in self._manager.zones.values():
|
||||
if not zone.freezes_done:
|
||||
continue
|
||||
zone.pause()
|
||||
|
||||
self._manager.global_freezes.append(self)
|
||||
|
||||
|
@ -338,3 +338,24 @@ async def test_simple_zone_timeout_zone_with_timeout_exeption() -> None:
|
||||
raise RuntimeError
|
||||
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
|
||||
async def test_multiple_global_freezes(hass: HomeAssistant) -> None:
|
||||
"""Test multiple global freezes."""
|
||||
timeout = TimeoutManager()
|
||||
|
||||
async def background(delay: float) -> None:
|
||||
async with timeout.async_freeze():
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
async with timeout.async_timeout(0.1):
|
||||
task = hass.async_create_task(background(0.2))
|
||||
async with timeout.async_freeze():
|
||||
await asyncio.sleep(0.1)
|
||||
await task
|
||||
|
||||
async with timeout.async_timeout(0.1):
|
||||
task = hass.async_create_task(background(0.2))
|
||||
async with timeout.async_freeze():
|
||||
await asyncio.sleep(0.3)
|
||||
await task
|
||||
|
Loading…
x
Reference in New Issue
Block a user