mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Resolve auth_store loading race condition (#21794)
* Add lock in auth_store._async_load() * Python 3.5 does not like assert_called_once()
This commit is contained in:
committed by
Paulus Schoutsen
parent
3ff2d99cd6
commit
3d8673dbf8
@@ -1,4 +1,8 @@
|
||||
"""Tests for the auth store."""
|
||||
import asyncio
|
||||
|
||||
import asynctest
|
||||
|
||||
from homeassistant.auth import auth_store
|
||||
|
||||
|
||||
@@ -218,3 +222,21 @@ async def test_system_groups_store_id_and_name(hass, hass_storage):
|
||||
'name': auth_store.GROUP_NAME_READ_ONLY,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def test_loading_race_condition(hass):
|
||||
"""Test only one storage load called when concurrent loading occurred ."""
|
||||
store = auth_store.AuthStore(hass)
|
||||
with asynctest.patch(
|
||||
'homeassistant.helpers.entity_registry.async_get_registry',
|
||||
) as mock_registry, asynctest.patch(
|
||||
'homeassistant.helpers.storage.Store.async_load',
|
||||
) as mock_load:
|
||||
results = await asyncio.gather(
|
||||
store.async_get_users(),
|
||||
store.async_get_users(),
|
||||
)
|
||||
|
||||
mock_registry.assert_called_once_with(hass)
|
||||
mock_load.assert_called_once_with()
|
||||
assert results[0] == results[1]
|
||||
|
||||
Reference in New Issue
Block a user