Skip to content
Snippets Groups Projects
Unverified Commit c3c7b68c authored by Ziv's avatar Ziv Committed by GitHub
Browse files

Fix unhandled exceptions in dsmr (#33601)

* reordered the clearing of the closed Event so it can stay set at the end and not
leave a task waiting on close

* fixed the side effect so it returns one TimeoutError and after that success
Previously it reached the end of the single item list and threw an exception

* fixed the error. it doesn't happen on python 3.7.5 but CI is on 3.7.0

* fixed comment
parent 0a3ec6fe
Branches
Tags
No related merge requests found
......@@ -8,7 +8,8 @@ Entity to be updated with new values.
import asyncio
import datetime
from decimal import Decimal
from unittest.mock import Mock
from itertools import chain, repeat
from unittest.mock import DEFAULT, Mock
import asynctest
import pytest
......@@ -323,9 +324,10 @@ async def test_connection_errors_retry(hass, monkeypatch, mock_connection_factor
config = {"platform": "dsmr", "reconnect_interval": 0}
# override the mock to have it fail the first time
first_fail_connection_factory = Mock(
wraps=connection_factory, side_effect=[TimeoutError]
# override the mock to have it fail the first time and succeed after
first_fail_connection_factory = asynctest.CoroutineMock(
return_value=(transport, protocol),
side_effect=chain([TimeoutError], repeat(DEFAULT)),
)
monkeypatch.setattr(
......@@ -336,7 +338,7 @@ async def test_connection_errors_retry(hass, monkeypatch, mock_connection_factor
# wait for sleep to resolve
await hass.async_block_till_done()
assert first_fail_connection_factory.call_count == 2, "connecting not retried"
assert first_fail_connection_factory.call_count >= 2, "connecting not retried"
async def test_reconnect(hass, monkeypatch, mock_connection_factory):
......@@ -352,7 +354,6 @@ async def test_reconnect(hass, monkeypatch, mock_connection_factory):
async def wait_closed():
await closed.wait()
closed2.set()
closed.clear()
protocol.wait_closed = wait_closed
......@@ -365,9 +366,10 @@ async def test_reconnect(hass, monkeypatch, mock_connection_factory):
# wait for lock set to resolve
await closed2.wait()
closed2.clear()
assert not closed.is_set()
closed.clear()
closed.set()
await hass.async_block_till_done()
assert connection_factory.call_count >= 2, "connecting not retried"
# setting it so teardown can be successful
closed.set()
......@@ -8,13 +8,6 @@ IGNORE_UNCAUGHT_EXCEPTIONS = [
("tests.components.default_config.test_init", "test_setup"),
("tests.components.demo.test_init", "test_setting_up_demo"),
("tests.components.discovery.test_init", "test_discover_config_flow"),
("tests.components.dsmr.test_sensor", "test_default_setup"),
("tests.components.dsmr.test_sensor", "test_v4_meter"),
("tests.components.dsmr.test_sensor", "test_v5_meter"),
("tests.components.dsmr.test_sensor", "test_belgian_meter"),
("tests.components.dsmr.test_sensor", "test_belgian_meter_low"),
("tests.components.dsmr.test_sensor", "test_tcp"),
("tests.components.dsmr.test_sensor", "test_connection_errors_retry"),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_attributes"),
("tests.components.dyson.test_air_quality", "test_purecool_aiq_update_state"),
(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment