Avoid creating inner tasks to load storage (#117099)

This commit is contained in:
J. Nick Koston 2024-05-08 16:41:20 -05:00 committed by GitHub
parent ead69af27c
commit 03dcede211
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 16 deletions

View file

@ -1159,3 +1159,21 @@ async def test_store_manager_cleanup_after_stop(
assert store_manager.async_fetch("integration1") is None
assert store_manager.async_fetch("integration2") is None
await hass.async_stop(force=True)
async def test_storage_concurrent_load(hass: HomeAssistant) -> None:
"""Test that we can load the store concurrently."""
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY)
async def _load_store():
await asyncio.sleep(0)
return "data"
with patch.object(store, "_async_load", side_effect=_load_store):
# Test that we can load the store concurrently
loads = await asyncio.gather(
store.async_load(), store.async_load(), store.async_load()
)
for load in loads:
assert load == "data"