Skip to content

Commit c3365e1

Browse files
authored
Clear cache between ServiceTypesQuery tests (#466)
- Ensures the test relies on the ZeroconfServiceTypes.find making the correct calls instead of the cache from the previous call
1 parent c1ed987 commit c3365e1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

zeroconf/test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def has_working_ipv6():
8282
return False
8383

8484

85+
def _clear_cache(zc):
86+
for name in zc.cache.names():
87+
for record in zc.cache.entries_with_name(name):
88+
zc.cache.remove(record)
89+
90+
8591
class TestDunder(unittest.TestCase):
8692
def test_dns_text_repr(self):
8793
# There was an issue on Python 3 that prevented DNSText's repr
@@ -1120,6 +1126,7 @@ def test_integration_with_listener(self):
11201126
try:
11211127
service_types = ZeroconfServiceTypes.find(interfaces=['127.0.0.1'], timeout=0.5)
11221128
assert type_ in service_types
1129+
_clear_cache(zeroconf_registrar)
11231130
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
11241131
assert type_ in service_types
11251132

@@ -1152,6 +1159,7 @@ def test_integration_with_listener_v6_records(self):
11521159
try:
11531160
service_types = ZeroconfServiceTypes.find(interfaces=['127.0.0.1'], timeout=0.5)
11541161
assert type_ in service_types
1162+
_clear_cache(zeroconf_registrar)
11551163
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
11561164
assert type_ in service_types
11571165

@@ -1183,6 +1191,7 @@ def test_integration_with_listener_ipv6(self):
11831191
try:
11841192
service_types = ZeroconfServiceTypes.find(ip_version=r.IPVersion.V6Only, timeout=0.5)
11851193
assert type_ in service_types
1194+
_clear_cache(zeroconf_registrar)
11861195
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
11871196
assert type_ in service_types
11881197

@@ -1214,6 +1223,7 @@ def test_integration_with_subtype_and_listener(self):
12141223
try:
12151224
service_types = ZeroconfServiceTypes.find(interfaces=['127.0.0.1'], timeout=0.5)
12161225
assert discovery_type in service_types
1226+
_clear_cache(zeroconf_registrar)
12171227
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
12181228
assert discovery_type in service_types
12191229

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

12921302
# clear the answer cache to force query
1293-
for name in zeroconf_browser.cache.names():
1294-
for record in zeroconf_browser.cache.entries_with_name(name):
1295-
zeroconf_browser.cache.remove(record)
1303+
_clear_cache(zeroconf_browser)
12961304

12971305
cached_info = ServiceInfo(type_, registration_name)
12981306
cached_info.load_from_cache(zeroconf_browser)

0 commit comments

Comments
 (0)