Updated non-blocking timout to 10 seconds for fixing timeout issues. (#23930)
* Updated non-blocking timout to 10 seconds for fixing timeout issues. * Added failed bridge fixture for faster unit tests.
This commit is contained in:
parent
ff867a7d57
commit
d7d83c683d
3 changed files with 26 additions and 2 deletions
|
@ -63,7 +63,7 @@ async def async_setup(hass: HomeAssistantType, config: Dict) -> bool:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
device_data = await wait_for(
|
device_data = await wait_for(
|
||||||
v2bridge.queue.get(), timeout=5.0, loop=hass.loop)
|
v2bridge.queue.get(), timeout=10.0, loop=hass.loop)
|
||||||
except (Asyncio_TimeoutError, RuntimeError):
|
except (Asyncio_TimeoutError, RuntimeError):
|
||||||
_LOGGER.exception("failed to get response from device")
|
_LOGGER.exception("failed to get response from device")
|
||||||
await v2bridge.stop()
|
await v2bridge.stop()
|
||||||
|
|
|
@ -108,3 +108,25 @@ def mock_bridge_fixture() -> Generator[None, Any, None]:
|
||||||
|
|
||||||
for patcher in patchers:
|
for patcher in patchers:
|
||||||
patcher.stop()
|
patcher.stop()
|
||||||
|
|
||||||
|
|
||||||
|
@fixture(name='mock_failed_bridge')
|
||||||
|
def mock_failed_bridge_fixture() -> Generator[None, Any, None]:
|
||||||
|
"""Fixture for mocking aioswitcher.bridge.SwitcherV2Bridge."""
|
||||||
|
async def mock_queue():
|
||||||
|
"""Mock asyncio's Queue."""
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
patchers = [
|
||||||
|
patch('aioswitcher.bridge.SwitcherV2Bridge.start', return_value=None),
|
||||||
|
patch('aioswitcher.bridge.SwitcherV2Bridge.stop', return_value=None),
|
||||||
|
patch('aioswitcher.bridge.SwitcherV2Bridge.queue', get=mock_queue)
|
||||||
|
]
|
||||||
|
|
||||||
|
for patcher in patchers:
|
||||||
|
patcher.start()
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
for patcher in patchers:
|
||||||
|
patcher.stop()
|
||||||
|
|
|
@ -13,7 +13,9 @@ from .consts import (
|
||||||
DUMMY_REMAINING_TIME, MANDATORY_CONFIGURATION)
|
DUMMY_REMAINING_TIME, MANDATORY_CONFIGURATION)
|
||||||
|
|
||||||
|
|
||||||
async def test_failed_config(hass: HomeAssistantType) -> None:
|
async def test_failed_config(
|
||||||
|
hass: HomeAssistantType,
|
||||||
|
mock_failed_bridge: Generator[None, Any, None]) -> None:
|
||||||
"""Test failed configuration."""
|
"""Test failed configuration."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, MANDATORY_CONFIGURATION) is False
|
hass, DOMAIN, MANDATORY_CONFIGURATION) is False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue