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
4 changes: 3 additions & 1 deletion tests/services/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ def mock_record_update_incoming_msg(
service_updated_event.clear()
service_text = b"path=/~matt2/"
_inject_response(zeroconf, mock_record_update_incoming_msg(r.ServiceStateChange.Updated))
service_updated_event.wait(wait_time)
# Negative assertion: a duplicate update must NOT fire the listener. The wait
# always times out, so keep the budget short rather than reusing wait_time.
service_updated_event.wait(0.3)
assert service_added_count == 1
assert service_updated_count == 2
assert service_removed_count == 0
Expand Down
16 changes: 8 additions & 8 deletions tests/services/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def test_integration_with_listener(disable_duplicate_packet_suppression):
)
zeroconf_registrar.registry.async_add(info)
try:
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=2)
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
assert type_ in service_types
_clear_cache(zeroconf_registrar)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=2)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
assert type_ in service_types

finally:
Expand Down Expand Up @@ -79,10 +79,10 @@ def test_integration_with_listener_v6_records(disable_duplicate_packet_suppressi
)
zeroconf_registrar.registry.async_add(info)
try:
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=2)
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
assert type_ in service_types
_clear_cache(zeroconf_registrar)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=2)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
assert type_ in service_types

finally:
Expand Down Expand Up @@ -115,10 +115,10 @@ def test_integration_with_listener_ipv6(disable_duplicate_packet_suppression):
)
zeroconf_registrar.registry.async_add(info)
try:
service_types = ZeroconfServiceTypes.find(ip_version=r.IPVersion.V6Only, timeout=2)
service_types = ZeroconfServiceTypes.find(ip_version=r.IPVersion.V6Only, timeout=0.5)
assert type_ in service_types
_clear_cache(zeroconf_registrar)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=2)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
assert type_ in service_types

finally:
Expand Down Expand Up @@ -147,10 +147,10 @@ def test_integration_with_subtype_and_listener(disable_duplicate_packet_suppress
)
zeroconf_registrar.registry.async_add(info)
try:
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=2)
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
assert discovery_type in service_types
_clear_cache(zeroconf_registrar)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=2)
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
assert discovery_type in service_types

finally:
Expand Down
18 changes: 9 additions & 9 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def sync_code():


@pytest.mark.asyncio
async def test_async_service_registration() -> None:
async def test_async_service_registration(quick_timing: None) -> None:
"""Test registering services broadcasts the registration by default."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test1-srvc-type._tcp.local."
Expand Down Expand Up @@ -193,7 +193,7 @@ def update_service(self, zeroconf: Zeroconf, type: str, name: str) -> None:


@pytest.mark.asyncio
async def test_async_service_registration_with_server_missing() -> None:
async def test_async_service_registration_with_server_missing(quick_timing: None) -> None:
"""Test registering a service with the server not specified.

For backwards compatibility, the server should be set to the
Expand Down Expand Up @@ -394,7 +394,7 @@ def update_service(self, zeroconf: Zeroconf, type: str, name: str) -> None:


@pytest.mark.asyncio
async def test_async_service_registration_name_conflict() -> None:
async def test_async_service_registration_name_conflict(quick_timing: None) -> None:
"""Test registering services throws on name conflict."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test-srvc2-type._tcp.local."
Expand Down Expand Up @@ -503,7 +503,7 @@ async def test_async_service_registration_name_strict_check(quick_timing: None)


@pytest.mark.asyncio
async def test_async_tasks() -> None:
async def test_async_tasks(quick_timing: None) -> None:
"""Test awaiting broadcast tasks"""

aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
Expand Down Expand Up @@ -605,7 +605,7 @@ async def test_async_wait_unblocks_on_update() -> None:


@pytest.mark.asyncio
async def test_service_info_async_request() -> None:
async def test_service_info_async_request(quick_timing: None) -> None:
"""Test registering services broadcasts and query with AsyncServceInfo.async_request."""
if not has_working_ipv6() or os.environ.get("SKIP_IPV6"):
pytest.skip("Requires IPv6")
Expand Down Expand Up @@ -700,7 +700,7 @@ async def test_service_info_async_request() -> None:
# Generating the race condition is almost impossible
# without patching since its a TOCTOU race
with patch("zeroconf.asyncio.AsyncServiceInfo._is_complete", False):
await aiosinfo.async_request(aiozc.zeroconf, 3000)
await aiosinfo.async_request(aiozc.zeroconf, 500)
assert aiosinfo is not None
assert aiosinfo.addresses == [socket.inet_aton("10.0.1.3")]

Expand All @@ -714,7 +714,7 @@ async def test_service_info_async_request() -> None:


@pytest.mark.asyncio
async def test_async_service_browser() -> None:
async def test_async_service_browser(quick_timing: None) -> None:
"""Test AsyncServiceBrowser."""
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
type_ = "_test9-srvc-type._tcp.local."
Expand Down Expand Up @@ -906,10 +906,10 @@ async def test_async_zeroconf_service_types(quick_timing: None) -> None:
await asyncio.sleep(0.2)
_clear_cache(zeroconf_registrar.zeroconf)
try:
service_types = await AsyncZeroconfServiceTypes.async_find(interfaces=["127.0.0.1"], timeout=2)
service_types = await AsyncZeroconfServiceTypes.async_find(interfaces=["127.0.0.1"], timeout=0.5)
assert type_ in service_types
_clear_cache(zeroconf_registrar.zeroconf)
service_types = await AsyncZeroconfServiceTypes.async_find(aiozc=zeroconf_registrar, timeout=2)
service_types = await AsyncZeroconfServiceTypes.async_find(aiozc=zeroconf_registrar, timeout=0.5)
assert type_ in service_types

finally:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def _process_outgoing_packet(out):
nbr_answers = nbr_additionals = nbr_authorities = 0
zc.close()

@pytest.mark.usefixtures("quick_timing")
def test_name_conflicts(self):
# instantiate a zeroconf instance
zc = Zeroconf(interfaces=["127.0.0.1"])
Expand Down Expand Up @@ -189,6 +190,7 @@ def test_name_conflicts(self):
zc.register_service(conflicting_info)
zc.close()

@pytest.mark.usefixtures("quick_timing")
def test_register_and_lookup_type_by_uppercase_name(self):
# instantiate a zeroconf instance
zc = Zeroconf(interfaces=["127.0.0.1"])
Expand Down
3 changes: 3 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import unittest.mock
from unittest.mock import patch

import pytest

import zeroconf as r
from zeroconf import ServiceInfo, Zeroconf, const

Expand Down Expand Up @@ -68,6 +70,7 @@ def test_same_name(self):
generated.add_question(question)
r.DNSIncoming(generated.packets()[0])

@pytest.mark.usefixtures("quick_timing")
def test_verify_name_change_with_lots_of_names(self):
# instantiate a zeroconf instance
zc = Zeroconf(interfaces=["127.0.0.1"])
Expand Down
3 changes: 2 additions & 1 deletion tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def teardown_module():


class ListenerTest(unittest.TestCase):
@pytest.mark.usefixtures("quick_timing")
def test_integration_with_listener_class(self):
sub_service_added = Event()
service_added = Event()
Expand Down Expand Up @@ -113,7 +114,7 @@ def update_service(self, zeroconf, type, name):
assert service_added.is_set()

# short pause to allow multicast timers to expire
time.sleep(3)
time.sleep(0.5)

zeroconf_browser.add_service_listener(type_, DuplicateListener())
duplicate_service_added.wait(
Expand Down
Loading