Skip to content
Merged
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
14 changes: 11 additions & 3 deletions zeroconf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def has_working_ipv6():
return False


def _clear_cache(zc):
for name in zc.cache.names():
for record in zc.cache.entries_with_name(name):
zc.cache.remove(record)


class TestDunder(unittest.TestCase):
def test_dns_text_repr(self):
# There was an issue on Python 3 that prevented DNSText's repr
Expand Down Expand Up @@ -1120,6 +1126,7 @@ def test_integration_with_listener(self):
try:
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=0.5)
assert type_ in service_types

Expand Down Expand Up @@ -1152,6 +1159,7 @@ def test_integration_with_listener_v6_records(self):
try:
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=0.5)
assert type_ in service_types

Expand Down Expand Up @@ -1183,6 +1191,7 @@ def test_integration_with_listener_ipv6(self):
try:
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=0.5)
assert type_ in service_types

Expand Down Expand Up @@ -1214,6 +1223,7 @@ def test_integration_with_subtype_and_listener(self):
try:
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=0.5)
assert discovery_type in service_types

Expand Down Expand Up @@ -1290,9 +1300,7 @@ def update_service(self, zeroconf, type, name):
time.sleep(3)

# clear the answer cache to force query
for name in zeroconf_browser.cache.names():
for record in zeroconf_browser.cache.entries_with_name(name):
zeroconf_browser.cache.remove(record)
_clear_cache(zeroconf_browser)

cached_info = ServiceInfo(type_, registration_name)
cached_info.load_from_cache(zeroconf_browser)
Expand Down