2323from zeroconf ._utils .net import IPVersion
2424from zeroconf .asyncio import AsyncZeroconf
2525
26- from .. import _inject_response , has_working_ipv6
26+ from .. import QUICK_REQUEST_TIMEOUT_MS , _inject_response , has_working_ipv6
2727
2828log = logging .getLogger ("zeroconf" )
2929original_logging_level = logging .NOTSET
@@ -511,6 +511,7 @@ def get_service_info_helper(zc, type, name, timeout):
511511 zc .remove_all_service_listeners ()
512512 zc .close ()
513513
514+ @pytest .mark .usefixtures ("quick_request_timing" )
514515 def test_get_info_single (self ):
515516 zc = r .Zeroconf (interfaces = ["127.0.0.1" ])
516517
@@ -556,6 +557,9 @@ def get_service_info_helper(zc, type, name):
556557 args = (zc , service_type , service_name ),
557558 )
558559 helper_thread .start ()
560+ # Positive wait — the first query fires within
561+ # `_LISTENER_TIME` + jitter (~15ms under
562+ # `quick_request_timing`, ~320ms without).
559563 wait_time = 1
560564
561565 # Expect query for SRV, TXT, A, AAAA
@@ -568,7 +572,10 @@ def get_service_info_helper(zc, type, name):
568572 assert r .DNSQuestion (service_name , const ._TYPE_AAAA , const ._CLASS_IN ) in last_sent .questions
569573 assert service_info is None
570574
571- # Expect no further queries
575+ # Expect no further queries — under `quick_request_timing`
576+ # the next query would have fired ~15ms after the previous
577+ # send, so 100ms is plenty of headroom for the negative
578+ # assertion.
572579 last_sent = None
573580 send_event .clear ()
574581 _inject_response (
@@ -602,7 +609,7 @@ def get_service_info_helper(zc, type, name):
602609 ]
603610 ),
604611 )
605- send_event .wait (wait_time )
612+ send_event .wait (0.1 )
606613 assert last_sent is None
607614 assert service_info is not None
608615
@@ -985,7 +992,7 @@ def test_serviceinfo_accepts_bytes_or_string_dict():
985992 assert info_service .dns_text ().text == b"\x0e path=/~paulsm/"
986993
987994
988- def test_asking_qu_questions ():
995+ def test_asking_qu_questions (quick_request_timing ):
989996 """Verify explicitly asking QU questions."""
990997 type_ = "_quservice._tcp.local."
991998 zeroconf = r .Zeroconf (interfaces = ["127.0.0.1" ])
@@ -1004,12 +1011,14 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
10041011
10051012 # patch the zeroconf send
10061013 with patch .object (zeroconf , "async_send" , send ):
1007- zeroconf .get_service_info (f"name.{ type_ } " , type_ , 500 , question_type = r .DNSQuestionType .QU )
1014+ zeroconf .get_service_info (
1015+ f"name.{ type_ } " , type_ , QUICK_REQUEST_TIMEOUT_MS , question_type = r .DNSQuestionType .QU
1016+ )
10081017 assert first_outgoing .questions [0 ].unicast is True # type: ignore[union-attr]
10091018 zeroconf .close ()
10101019
10111020
1012- def test_asking_qm_questions ():
1021+ def test_asking_qm_questions (quick_request_timing ):
10131022 """Verify explicitly asking QM questions."""
10141023 type_ = "_quservice._tcp.local."
10151024 zeroconf = r .Zeroconf (interfaces = ["127.0.0.1" ])
@@ -1028,7 +1037,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
10281037
10291038 # patch the zeroconf send
10301039 with patch .object (zeroconf , "async_send" , send ):
1031- zeroconf .get_service_info (f"name.{ type_ } " , type_ , 500 , question_type = r .DNSQuestionType .QM )
1040+ zeroconf .get_service_info (
1041+ f"name.{ type_ } " , type_ , QUICK_REQUEST_TIMEOUT_MS , question_type = r .DNSQuestionType .QM
1042+ )
10321043 assert first_outgoing .questions [0 ].unicast is False # type: ignore[union-attr]
10331044 zeroconf .close ()
10341045
0 commit comments