Skip to content

Commit 3d9354b

Browse files
committed
Attempt to fix ghost error in CI.
1 parent 27666ed commit 3d9354b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

requirements.test.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
asyncmock
2-
mypy
1+
asyncmock ~= 0.4
2+
mypy ~= 1.19
33
powersensor_local
4-
pytest
5-
pytest-asyncio
4+
pytest ~= 9.0
5+
pytest-asyncio ~= 1.3
66
pytest-homeassistant-custom-component
77
zeroconf

tests/test_discovery_service.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
MAC = "a4cf1218f158"
2525

2626

27-
logging.getLogger().setLevel(logging.CRITICAL)
28-
29-
3027
@pytest.fixture
3128
def mock_service_info():
3229
"""Create a mock service info."""
@@ -108,7 +105,6 @@ async def test_discovery_add_and_remove(
108105

109106
service.remove_service(mock_zc, zc_info.type, zc_info.name)
110107

111-
# mock_zc.get_service_info.assert_called_once_with(zc_info.type, zc_info.name)
112108
mock_zc.get_service_info.assert_called_once_with(zc_info.type, zc_info.name)
113109
mock_send.assert_not_called()
114110
await asyncio.sleep(service._debounce_seconds + 1)
@@ -178,20 +174,30 @@ async def test_discovery_remove_cancel(
178174
# reset mock_send
179175
mock_send = Mock()
180176
monkeypatch.setattr(PowersensorServiceListener, "dispatch", mock_send)
181-
# cache plug data for checking
177+
178+
# ensure we start from a known state
179+
assert len(service._pending_removals) == 0
182180

183181
service.remove_service(mock_zc, zc_info.type, zc_info.name)
184182

185-
# mock_zc.get_service_info.assert_called_once_with(zc_info.type, zc_info.name)
186183
mock_zc.get_service_info.assert_called_once_with(zc_info.type, zc_info.name)
187184
mock_send.assert_not_called()
185+
assert len(service._pending_removals) == 1
188186

187+
# give the remove a head start before triggering the cancellation
188+
await asyncio.sleep(0.5)
189+
190+
# re-add the service, which should cancel the pending remove
189191
service.add_service(mock_zc, zc_info.type, zc_info.name)
190192
assert mock_zc.get_service_info.call_count == 2
191193
mock_zc.get_service_info.assert_has_calls(
192194
[call(zc_info.type, zc_info.name), call(zc_info.type, zc_info.name)]
193195
)
194196

197+
# let the removal task do its cancellation stuff
198+
await asyncio.sleep(0.5)
199+
assert len(service._pending_removals) == 0
200+
195201

196202
@pytest.mark.asyncio
197203
async def test_discovery_add_and_two_remove_calls(

0 commit comments

Comments
 (0)