Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
# Timeout for ZeroconfServiceTypes.find() / AsyncZeroconfServiceTypes.async_find()
# in loopback integration tests. `find()` is just `time.sleep(timeout)` —
# it doesn't short-circuit on the first matching response — so the
# timeout becomes a lower bound on the test runtime. On loopback the
# registrar's response lands within a few ms; 200ms is ~50x headroom.
LOOPBACK_FIND_TIMEOUT = 0.2
# timeout becomes a lower bound on the test runtime. Callers MUST use
# the `quick_timing` fixture, which shrinks the browser's first-query
# delay from RFC 6762 §5.2's 20-120ms window to 1-5ms; with that shave
# the registrar's response lands inside ~10ms and 75ms is ~7x headroom.
LOOPBACK_FIND_TIMEOUT = 0.075


class QuestionHistoryWithoutSuppression(QuestionHistory):
Expand Down
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from zeroconf import _core, const
from zeroconf._handlers import query_handler
from zeroconf._services import browser as service_browser
from zeroconf._services import info as service_info


Expand Down Expand Up @@ -46,18 +47,21 @@ def disable_duplicate_packet_suppression():

@pytest.fixture
def quick_timing() -> Generator[None]:
"""Shorten the probe/announce/goodbye intervals for tests on loopback.
"""Shorten the probe/announce/goodbye/first-query intervals for tests on loopback.

The production values (_CHECK_TIME=500ms, _REGISTER_TIME=225ms,
_UNREGISTER_TIME=125ms) exist for RFC 6762 interop on real
networks. Tests on 127.0.0.1 do not need them and pay 1-2s per
register/unregister cycle without this fixture. Opt in by adding
`quick_timing` to a test's argument list.
_UNREGISTER_TIME=125ms, _FIRST_QUERY_DELAY_RANDOM_INTERVAL=20-120ms)
exist for RFC 6762 interop on real networks (§8.1 thundering-herd
avoidance for probing, §5.2 for the initial-query delay). Tests on
127.0.0.1 do not need them and pay 1-2s per register/unregister
cycle and 20-120ms per ServiceBrowser startup without this fixture.
Opt in by adding `quick_timing` to a test's argument list.
"""
with (
patch.object(_core, "_CHECK_TIME", 10),
patch.object(_core, "_REGISTER_TIME", 10),
patch.object(_core, "_UNREGISTER_TIME", 10),
patch.object(service_browser, "_FIRST_QUERY_DELAY_RANDOM_INTERVAL", (1, 5)),
):
yield

Expand Down
8 changes: 4 additions & 4 deletions tests/services/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def teardown_module():
log.setLevel(original_logging_level)


def test_integration_with_listener(disable_duplicate_packet_suppression):
def test_integration_with_listener(quick_timing, disable_duplicate_packet_suppression):
type_ = "_test-listen-type._tcp.local."
name = "xxxyyy"
registration_name = f"{name}.{type_}"
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_integration_with_listener(disable_duplicate_packet_suppression):

@unittest.skipIf(not has_working_ipv6(), "Requires IPv6")
@unittest.skipIf(os.environ.get("SKIP_IPV6"), "IPv6 tests disabled")
def test_integration_with_listener_v6_records(disable_duplicate_packet_suppression):
def test_integration_with_listener_v6_records(quick_timing, disable_duplicate_packet_suppression):
type_ = "_test-listenv6rec-type._tcp.local."
name = "xxxyyy"
registration_name = f"{name}.{type_}"
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_integration_with_listener_v6_records(disable_duplicate_packet_suppressi
sys.platform == "darwin" and os.environ.get("GITHUB_ACTIONS") == "true",
"IPv6 multicast not working on macOS GitHub Actions",
)
def test_integration_with_listener_ipv6(disable_duplicate_packet_suppression):
def test_integration_with_listener_ipv6(quick_timing, disable_duplicate_packet_suppression):
type_ = "_test-listenv6ip-type._tcp.local."
name = "xxxyyy"
registration_name = f"{name}.{type_}"
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_integration_with_listener_ipv6(disable_duplicate_packet_suppression):
zeroconf_registrar.close()


def test_integration_with_subtype_and_listener(disable_duplicate_packet_suppression):
def test_integration_with_subtype_and_listener(quick_timing, disable_duplicate_packet_suppression):
subtype_ = "_subtype._sub"
type_ = "_listen._tcp.local."
name = "xxxyyy"
Expand Down
Loading