Skip to content

Commit a662920

Browse files
committed
test: name the quick_request_timing test timeout (QUICK_REQUEST_TIMEOUT_MS)
The 50ms get_service_info / async_request timeout used by the three tests that opt in to `quick_request_timing` was a bare integer literal. Hoist it to a `QUICK_REQUEST_TIMEOUT_MS` constant in `tests/__init__.py` so the relationship to the fixture (which shortens the initial-query delay to ~15ms) is documented and the value lives in one place.
1 parent e240afd commit a662920

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

tests/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535

3636
_MONOTONIC_RESOLUTION = time.get_clock_info("monotonic").resolution
3737

38+
# get_service_info / async_request timeout for tests using the
39+
# `quick_request_timing` fixture. The fixture cuts the initial-query
40+
# delay to ~15ms (10ms _LISTENER_TIME + 1-5ms jitter), so 50ms is
41+
# ample headroom for tests that only need to observe the first one
42+
# or two queries.
43+
QUICK_REQUEST_TIMEOUT_MS = 50
44+
3845

3946
class QuestionHistoryWithoutSuppression(QuestionHistory):
4047
def suppresses(self, question: DNSQuestion, now: float, known_answers: set[DNSRecord]) -> bool:

tests/services/test_info.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from zeroconf._utils.net import IPVersion
2424
from 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

2828
log = logging.getLogger("zeroconf")
2929
original_logging_level = logging.NOTSET
@@ -1006,7 +1006,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
10061006

10071007
# patch the zeroconf send
10081008
with patch.object(zeroconf, "async_send", send):
1009-
zeroconf.get_service_info(f"name.{type_}", type_, 50, question_type=r.DNSQuestionType.QU)
1009+
zeroconf.get_service_info(
1010+
f"name.{type_}", type_, QUICK_REQUEST_TIMEOUT_MS, question_type=r.DNSQuestionType.QU
1011+
)
10101012
assert first_outgoing.questions[0].unicast is True # type: ignore[union-attr]
10111013
zeroconf.close()
10121014

@@ -1030,7 +1032,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
10301032

10311033
# patch the zeroconf send
10321034
with patch.object(zeroconf, "async_send", send):
1033-
zeroconf.get_service_info(f"name.{type_}", type_, 50, question_type=r.DNSQuestionType.QM)
1035+
zeroconf.get_service_info(
1036+
f"name.{type_}", type_, QUICK_REQUEST_TIMEOUT_MS, question_type=r.DNSQuestionType.QM
1037+
)
10341038
assert first_outgoing.questions[0].unicast is False # type: ignore[union-attr]
10351039
zeroconf.close()
10361040

tests/test_asyncio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from zeroconf.const import _LISTENER_TIME
4444

4545
from . import (
46+
QUICK_REQUEST_TIMEOUT_MS,
4647
QuestionHistoryWithoutSuppression,
4748
_clear_cache,
4849
has_working_ipv6,
@@ -1184,9 +1185,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
11841185
aiosinfo = AsyncServiceInfo(type_, registration_name)
11851186
# Patch _is_complete so we send multiple times. Under
11861187
# `quick_request_timing` both the QU query at 0ms and the QM
1187-
# query at ~15ms land well inside 50ms.
1188+
# query at ~15ms land well inside QUICK_REQUEST_TIMEOUT_MS.
11881189
with patch("zeroconf.asyncio.AsyncServiceInfo._is_complete", False):
1189-
await aiosinfo.async_request(aiozc.zeroconf, 50)
1190+
await aiosinfo.async_request(aiozc.zeroconf, QUICK_REQUEST_TIMEOUT_MS)
11901191
try:
11911192
assert first_outgoing.questions[0].unicast is True # type: ignore[union-attr]
11921193
assert second_outgoing.questions[0].unicast is False # type: ignore[attr-defined]

0 commit comments

Comments
 (0)