Skip to content

Commit 37e3ceb

Browse files
committed
test: cover connection_lost guard branches
1 parent b262b0e commit 37e3ceb

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tests/test_engine.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
import zeroconf as r
13-
from zeroconf import _engine, const
13+
from zeroconf import _engine, _listener, const
1414
from zeroconf.asyncio import AsyncZeroconf
1515

1616
log = logging.getLogger("zeroconf")
@@ -108,6 +108,24 @@ async def test_connection_lost_prunes_transport(aiozc_loopback: AsyncZeroconf) -
108108
assert protocol not in engine.protocols
109109

110110

111+
@pytest.mark.asyncio
112+
async def test_connection_lost_without_transport_is_noop(aiozc_loopback: AsyncZeroconf) -> None:
113+
"""connection_lost on a listener that never bound a transport leaves the lists intact."""
114+
await aiozc_loopback.zeroconf.async_wait_for_start()
115+
engine = aiozc_loopback.zeroconf.engine
116+
reader_count = len(engine.readers)
117+
sender_count = len(engine.senders)
118+
protocol_count = len(engine.protocols)
119+
120+
orphan = _listener.AsyncListener(aiozc_loopback.zeroconf)
121+
assert orphan.transport is None
122+
orphan.connection_lost(None)
123+
124+
assert len(engine.readers) == reader_count
125+
assert len(engine.senders) == sender_count
126+
assert len(engine.protocols) == protocol_count
127+
128+
111129
@pytest.mark.asyncio
112130
async def test_async_close_propagates_outer_cancellation(aiozc_loopback: AsyncZeroconf) -> None:
113131
"""Outer-task cancellation while awaiting setup propagates to the caller."""

0 commit comments

Comments
 (0)