Set default parallel_update value should base on async_update (#22149)
* Set default parallel_update value should base on async_update * Set default parallel_update value should base on async_update * Delay the parallel_update_semaphore creation * Remove outdated comment
This commit is contained in:
parent
a62c116959
commit
e85b089eff
3 changed files with 242 additions and 121 deletions
|
@ -251,80 +251,126 @@ def test_updated_state_used_for_entity_id(hass):
|
|||
assert entity_ids[0] == "test_domain.living_room"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_parallel_updates_async_platform(hass):
|
||||
"""Warn we log when platform setup takes a long time."""
|
||||
async def test_parallel_updates_async_platform(hass):
|
||||
"""Test async platform does not have parallel_updates limit by default."""
|
||||
platform = MockPlatform()
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_update(*args, **kwargs):
|
||||
pass
|
||||
|
||||
platform.async_setup_platform = mock_update
|
||||
|
||||
loader.set_component(hass, 'test_domain.platform', platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
component._platforms = {}
|
||||
|
||||
yield from component.async_setup({
|
||||
await component.async_setup({
|
||||
DOMAIN: {
|
||||
'platform': 'platform',
|
||||
}
|
||||
})
|
||||
|
||||
handle = list(component._platforms.values())[-1]
|
||||
|
||||
assert handle.parallel_updates is None
|
||||
|
||||
class AsyncEntity(MockEntity):
|
||||
"""Mock entity that has async_update."""
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_parallel_updates_async_platform_with_constant(hass):
|
||||
"""Warn we log when platform setup takes a long time."""
|
||||
async def async_update(self):
|
||||
pass
|
||||
|
||||
entity = AsyncEntity()
|
||||
await handle.async_add_entities([entity])
|
||||
assert entity.parallel_updates is None
|
||||
|
||||
|
||||
async def test_parallel_updates_async_platform_with_constant(hass):
|
||||
"""Test async platform can set parallel_updates limit."""
|
||||
platform = MockPlatform()
|
||||
platform.PARALLEL_UPDATES = 2
|
||||
|
||||
loader.set_component(hass, 'test_domain.platform', platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
component._platforms = {}
|
||||
|
||||
await component.async_setup({
|
||||
DOMAIN: {
|
||||
'platform': 'platform',
|
||||
}
|
||||
})
|
||||
|
||||
handle = list(component._platforms.values())[-1]
|
||||
|
||||
assert handle.parallel_updates == 2
|
||||
|
||||
class AsyncEntity(MockEntity):
|
||||
"""Mock entity that has async_update."""
|
||||
|
||||
async def async_update(self):
|
||||
pass
|
||||
|
||||
entity = AsyncEntity()
|
||||
await handle.async_add_entities([entity])
|
||||
assert entity.parallel_updates is not None
|
||||
assert entity.parallel_updates._value == 2
|
||||
|
||||
|
||||
async def test_parallel_updates_sync_platform(hass):
|
||||
"""Test sync platform parallel_updates default set to 1."""
|
||||
platform = MockPlatform()
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_update(*args, **kwargs):
|
||||
pass
|
||||
|
||||
platform.async_setup_platform = mock_update
|
||||
platform.PARALLEL_UPDATES = 1
|
||||
|
||||
loader.set_component(hass, 'test_domain.platform', platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
component._platforms = {}
|
||||
|
||||
yield from component.async_setup({
|
||||
await component.async_setup({
|
||||
DOMAIN: {
|
||||
'platform': 'platform',
|
||||
}
|
||||
})
|
||||
|
||||
handle = list(component._platforms.values())[-1]
|
||||
assert handle.parallel_updates is None
|
||||
|
||||
assert handle.parallel_updates is not None
|
||||
class SyncEntity(MockEntity):
|
||||
"""Mock entity that has update."""
|
||||
|
||||
async def update(self):
|
||||
pass
|
||||
|
||||
entity = SyncEntity()
|
||||
await handle.async_add_entities([entity])
|
||||
assert entity.parallel_updates is not None
|
||||
assert entity.parallel_updates._value == 1
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_parallel_updates_sync_platform(hass):
|
||||
"""Warn we log when platform setup takes a long time."""
|
||||
platform = MockPlatform(setup_platform=lambda *args: None)
|
||||
async def test_parallel_updates_sync_platform_with_constant(hass):
|
||||
"""Test sync platform can set parallel_updates limit."""
|
||||
platform = MockPlatform()
|
||||
platform.PARALLEL_UPDATES = 2
|
||||
|
||||
loader.set_component(hass, 'test_domain.platform', platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
component._platforms = {}
|
||||
|
||||
yield from component.async_setup({
|
||||
await component.async_setup({
|
||||
DOMAIN: {
|
||||
'platform': 'platform',
|
||||
}
|
||||
})
|
||||
|
||||
handle = list(component._platforms.values())[-1]
|
||||
assert handle.parallel_updates == 2
|
||||
|
||||
assert handle.parallel_updates is not None
|
||||
class SyncEntity(MockEntity):
|
||||
"""Mock entity that has update."""
|
||||
|
||||
async def update(self):
|
||||
pass
|
||||
|
||||
entity = SyncEntity()
|
||||
await handle.async_add_entities([entity])
|
||||
assert entity.parallel_updates is not None
|
||||
assert entity.parallel_updates._value == 2
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue