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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ accelerated projects.
`_ANSWER_STRATEGY_POINTER = 1` in `query_handler.py` as a C int
assignment; the Python module dict never gets the binding.
`from zeroconf._handlers.query_handler import
_ANSWER_STRATEGY_POINTER` succeeds in pure-Python but raises
_ANSWER_STRATEGY_POINTER` succeeds in pure-Python but raises
`ImportError` under Cython. If you need the value visible from
Python (e.g. a test wants to assert on it), define both names —
a public `ANSWER_STRATEGY_POINTER = 1` Python binding plus a
Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import threading
from collections.abc import Generator
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -40,3 +41,21 @@ def disable_duplicate_packet_suppression():
"""
with patch.object(const, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0):
yield


@pytest.fixture
def quick_timing() -> Generator[None]:
"""Shorten the probe/announce/goodbye 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.
"""
with (
patch.object(_core, "_CHECK_TIME", 10),
patch.object(_core, "_REGISTER_TIME", 10),
patch.object(_core, "_UNREGISTER_TIME", 10),
):
yield
14 changes: 7 additions & 7 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def update_service(self, zeroconf: Zeroconf, type: str, name: str) -> None:


@pytest.mark.asyncio
async def test_async_service_registration_same_server_different_ports() -> None:
async def test_async_service_registration_same_server_different_ports(quick_timing: None) -> None:
"""Test registering services with the same server with different srv records."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test1-srvc-type._tcp.local."
Expand Down Expand Up @@ -327,7 +327,7 @@ def update_service(self, zeroconf: Zeroconf, type: str, name: str) -> None:


@pytest.mark.asyncio
async def test_async_service_registration_same_server_same_ports() -> None:
async def test_async_service_registration_same_server_same_ports(quick_timing: None) -> None:
"""Test registering services with the same server with the exact same srv record."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test1-srvc-type._tcp.local."
Expand Down Expand Up @@ -468,7 +468,7 @@ async def test_async_service_registration_name_does_not_match_type() -> None:


@pytest.mark.asyncio
async def test_async_service_registration_name_strict_check() -> None:
async def test_async_service_registration_name_strict_check(quick_timing: None) -> None:
"""Test registering services throws when the name does not comply."""
zc = Zeroconf(interfaces=["127.0.0.1"])
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
Expand Down Expand Up @@ -824,7 +824,7 @@ class MyServiceListener(ServiceListener):


@pytest.mark.asyncio
async def test_async_unregister_all_services() -> None:
async def test_async_unregister_all_services(quick_timing: None) -> None:
"""Test unregistering all services."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test1-srvc-type._tcp.local."
Expand Down Expand Up @@ -870,8 +870,8 @@ async def test_async_unregister_all_services() -> None:
_clear_cache(aiozc.zeroconf)

tasks = []
tasks.append(aiozc.async_get_service_info(type_, registration_name))
tasks.append(aiozc.async_get_service_info(type_, registration_name2))
tasks.append(aiozc.async_get_service_info(type_, registration_name, timeout=200))
tasks.append(aiozc.async_get_service_info(type_, registration_name2, timeout=200))
results = await asyncio.gather(*tasks)
assert results[0] is None
assert results[1] is None
Expand All @@ -883,7 +883,7 @@ async def test_async_unregister_all_services() -> None:


@pytest.mark.asyncio
async def test_async_zeroconf_service_types():
async def test_async_zeroconf_service_types(quick_timing: None) -> None:
type_ = "_test-srvc-type._tcp.local."
name = "xxxyyy"
registration_name = f"{name}.{type_}"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ async def test_multiple_sync_instances_stared_from_async_close():
await asyncio.sleep(0)


def test_shutdown_while_register_in_process():
def test_shutdown_while_register_in_process(quick_timing: None) -> None:
"""Test we can shutdown while registering a service in another thread."""

# instantiate a zeroconf instance
Expand Down
Loading