@@ -490,16 +490,10 @@ async def test_update_interfaces_does_not_rebuild_when_family_supported(
490490
491491
492492@pytest .mark .asyncio
493- async def test_update_interfaces_rebuilds_listen_socket_for_new_family (
494- aiozc_loopback : AsyncZeroconf ,
495- ) -> None :
496- """Adding an interface of an unsupported family rebuilds the listen socket once."""
493+ async def test_update_interfaces_rebuild_rejoins_kept_interfaces (aiozc_loopback : AsyncZeroconf ) -> None :
494+ """On a family-change rebuild, interfaces that stay are re-joined on the new listen socket."""
497495 engine = aiozc_loopback .zeroconf .engine
498496 await aiozc_loopback .zeroconf .async_wait_for_start ()
499- old_listen = engine ._listen_transport
500- assert old_listen is not None
501- assert old_listen .sock .family == socket .AF_INET # V4Only loopback instance
502- old_underlying = old_listen .transport
503497
504498 # Keep the existing IPv4 interface and add an IPv6 one (which the IPv4
505499 # listen socket can't join, forcing a rebuild).
@@ -514,25 +508,19 @@ async def fake_wrap(sock: object, is_sender: bool) -> _WrappedTransport:
514508
515509 with (
516510 patch .object (_engine , "normalize_interface_choice" , return_value = ["127.0.0.1" , v6 ]),
517- patch .object (_engine , "new_socket" , return_value = new_listen_sock ) as mock_new_socket ,
511+ patch .object (_engine , "new_socket" , return_value = new_listen_sock ),
518512 patch .object (_engine , "add_multicast_member" , return_value = True ) as mock_add ,
519513 patch .object (_engine , "new_respond_socket" , return_value = Mock ()),
520514 patch .object (_engine , "drop_multicast_member" ),
521515 patch .object (_engine .AsyncEngine , "_async_wrap_socket" , new = AsyncMock (side_effect = fake_wrap )),
522516 ):
523517 added = await engine .async_update_interfaces (["unused" ], IPVersion .All , False )
524518
525- # Rebuilt exactly once, the v6 sender added, the listen transport swapped,
526- mock_new_socket .assert_called_once ()
527519 assert added is True
528- assert engine ._listen_transport is not old_listen
529- # the kept IPv4 interface was re-joined on the new listen socket,
520+ # The kept IPv4 interface was re-joined on the new listen socket.
530521 assert any (
531522 call .args [0 ] is new_listen_sock and call .args [1 ] == "127.0.0.1" for call in mock_add .call_args_list
532523 )
533- # and the old listen socket closed and removed (no duplicate left behind).
534- assert old_underlying .is_closing ()
535- assert old_listen not in engine .readers
536524
537525
538526@pytest .mark .asyncio
0 commit comments