From d7d83c683d30b2336f85636c21af60ec8e95d77c Mon Sep 17 00:00:00 2001 From: Tomer Figenblat Date: Sun, 19 May 2019 12:24:59 +0300 Subject: [PATCH] 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. --- .../components/switcher_kis/__init__.py | 2 +- tests/components/switcher_kis/conftest.py | 22 +++++++++++++++++++ tests/components/switcher_kis/test_init.py | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switcher_kis/__init__.py b/homeassistant/components/switcher_kis/__init__.py index 43ca0abc2a05..9fb51992cd20 100644 --- a/homeassistant/components/switcher_kis/__init__.py +++ b/homeassistant/components/switcher_kis/__init__.py @@ -63,7 +63,7 @@ async def async_setup(hass: HomeAssistantType, config: Dict) -> bool: try: 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): _LOGGER.exception("failed to get response from device") await v2bridge.stop() diff --git a/tests/components/switcher_kis/conftest.py b/tests/components/switcher_kis/conftest.py index d0398d448e9c..9f961f72401a 100644 --- a/tests/components/switcher_kis/conftest.py +++ b/tests/components/switcher_kis/conftest.py @@ -108,3 +108,25 @@ def mock_bridge_fixture() -> Generator[None, Any, None]: for patcher in patchers: 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() diff --git a/tests/components/switcher_kis/test_init.py b/tests/components/switcher_kis/test_init.py index 0defb1137470..33d24903f943 100644 --- a/tests/components/switcher_kis/test_init.py +++ b/tests/components/switcher_kis/test_init.py @@ -13,7 +13,9 @@ from .consts import ( 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.""" assert await async_setup_component( hass, DOMAIN, MANDATORY_CONFIGURATION) is False