@@ -556,7 +556,7 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
556556
557557
558558@pytest .mark .asyncio
559- async def test_asking_default_is_asking_qm_questions_after_the_first_qu () :
559+ async def test_asking_default_is_asking_qm_questions_after_the_first_qu (quick_timing : None ) -> None :
560560 """Verify the service browser's first questions are QU and refresh queries are QM."""
561561 service_added = asyncio .Event ()
562562 service_removed = asyncio .Event ()
@@ -658,7 +658,7 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
658658
659659
660660@pytest .mark .asyncio
661- async def test_ttl_refresh_cancelled_rescue_query () :
661+ async def test_ttl_refresh_cancelled_rescue_query (quick_timing : None ) -> None :
662662 """Verify seeing a name again cancels the rescue query."""
663663 service_added = asyncio .Event ()
664664 service_removed = asyncio .Event ()
@@ -846,7 +846,7 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
846846 await aiozc .async_close ()
847847
848848
849- def test_legacy_record_update_listener () :
849+ def test_legacy_record_update_listener (quick_timing : None ) -> None :
850850 """Test a RecordUpdateListener that does not implement update_records."""
851851
852852 # instantiate a zeroconf instance
@@ -1499,10 +1499,15 @@ def update_service(self, zc, type_, name) -> None: # type: ignore[no-untyped-de
14991499 # Force the ttl to be 1 second
15001500 now = current_time_millis ()
15011501 for cache_record in list (zc .cache .cache .values ()):
1502- for record in cache_record :
1502+ for record in cache_record . values () :
15031503 zc .cache ._async_set_created_ttl (record , now , 1 )
15041504
1505- time .sleep (0.3 )
1505+ # Wait for the add callback to fire from the original inject_response.
1506+ for _ in range (30 ):
1507+ time .sleep (0.01 )
1508+ if len (callbacks ) == 1 :
1509+ break
1510+
15061511 info .port = 400
15071512 info ._dns_service_cache = None # we are mutating the record so clear the cache
15081513
@@ -1511,8 +1516,8 @@ def update_service(self, zc, type_, name) -> None: # type: ignore[no-untyped-de
15111516 mock_incoming_msg ([info .dns_service ()]),
15121517 )
15131518
1514- for _ in range (10 ):
1515- time .sleep (0.05 )
1519+ for _ in range (30 ):
1520+ time .sleep (0.01 )
15161521 if len (callbacks ) == 2 :
15171522 break
15181523
@@ -1521,8 +1526,19 @@ def update_service(self, zc, type_, name) -> None: # type: ignore[no-untyped-de
15211526 ("update" , type_ , registration_name ),
15221527 ]
15231528
1524- for _ in range (25 ):
1525- time .sleep (0.05 )
1529+ # Re-add every cached record with `created` in the past so the
1530+ # next reaper tick (0.01s) expires them and fires the remove
1531+ # callback, instead of waiting the full TTL in real time.
1532+ # Going through `_async_set_created_ttl` updates the expiration
1533+ # heap; mutating `record.created` directly would leave the heap
1534+ # entry pointing at the original `when` so the reaper never wakes.
1535+ past = current_time_millis () - 2000
1536+ for cache_record in list (zc .cache .cache .values ()):
1537+ for record in list (cache_record .values ()):
1538+ zc .cache ._async_set_created_ttl (record , past , 1 )
1539+
1540+ for _ in range (30 ):
1541+ time .sleep (0.01 )
15261542 if len (callbacks ) == 3 :
15271543 break
15281544
@@ -1567,7 +1583,7 @@ def test_scheduled_ptr_query_dunder_methods():
15671583
15681584
15691585@pytest .mark .asyncio
1570- async def test_close_zeroconf_without_browser_before_start_up_queries () :
1586+ async def test_close_zeroconf_without_browser_before_start_up_queries (quick_timing : None ) -> None :
15711587 """Test that we stop sending startup queries if zeroconf is closed out from under the browser."""
15721588 service_added = asyncio .Event ()
15731589 type_ = "_http._tcp.local."
@@ -1634,7 +1650,7 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
16341650
16351651
16361652@pytest .mark .asyncio
1637- async def test_close_zeroconf_without_browser_after_start_up_queries () :
1653+ async def test_close_zeroconf_without_browser_after_start_up_queries (quick_timing : None ) -> None :
16381654 """Test that we stop sending rescue queries if zeroconf is closed out from under the browser."""
16391655 service_added = asyncio .Event ()
16401656
0 commit comments