Skip to content

Commit fcef4dc

Browse files
committed
test: drop ZeroconfServiceTypes.find() timeouts from 500ms to 200ms on loopback
`ZeroconfServiceTypes.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. Each of these tests calls `find()` twice, paying 1s of pure sleep on top of ~200ms of setup. On loopback the registrar's response lands within a few ms, so 200ms is ~50× headroom. `test_async_zeroconf_service_types` also slept 200ms after `async_register_service` to let the last announce broadcast land — that one already has the `quick_timing` fixture (which patches _REGISTER_TIME=10ms), so 50ms is plenty. Speedups: - test_integration_with_listener: 1.28s → 0.67s - test_integration_with_subtype_and_listener: 1.27s → 0.66s - test_integration_with_listener_v6_records: 1.27s → 0.67s - test_integration_with_listener_ipv6 (same pattern, not in #1707 list): 0.67s - test_async_zeroconf_service_types: 1.54s → 0.77s
1 parent 91aa21d commit fcef4dc

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

tests/services/test_types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def test_integration_with_listener(disable_duplicate_packet_suppression):
4747
)
4848
zeroconf_registrar.registry.async_add(info)
4949
try:
50-
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
50+
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.2)
5151
assert type_ in service_types
5252
_clear_cache(zeroconf_registrar)
53-
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
53+
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.2)
5454
assert type_ in service_types
5555

5656
finally:
@@ -79,10 +79,10 @@ def test_integration_with_listener_v6_records(disable_duplicate_packet_suppressi
7979
)
8080
zeroconf_registrar.registry.async_add(info)
8181
try:
82-
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
82+
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.2)
8383
assert type_ in service_types
8484
_clear_cache(zeroconf_registrar)
85-
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
85+
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.2)
8686
assert type_ in service_types
8787

8888
finally:
@@ -115,10 +115,10 @@ def test_integration_with_listener_ipv6(disable_duplicate_packet_suppression):
115115
)
116116
zeroconf_registrar.registry.async_add(info)
117117
try:
118-
service_types = ZeroconfServiceTypes.find(ip_version=r.IPVersion.V6Only, timeout=0.5)
118+
service_types = ZeroconfServiceTypes.find(ip_version=r.IPVersion.V6Only, timeout=0.2)
119119
assert type_ in service_types
120120
_clear_cache(zeroconf_registrar)
121-
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
121+
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.2)
122122
assert type_ in service_types
123123

124124
finally:
@@ -147,10 +147,10 @@ def test_integration_with_subtype_and_listener(disable_duplicate_packet_suppress
147147
)
148148
zeroconf_registrar.registry.async_add(info)
149149
try:
150-
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.5)
150+
service_types = ZeroconfServiceTypes.find(interfaces=["127.0.0.1"], timeout=0.2)
151151
assert discovery_type in service_types
152152
_clear_cache(zeroconf_registrar)
153-
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.5)
153+
service_types = ZeroconfServiceTypes.find(zc=zeroconf_registrar, timeout=0.2)
154154
assert discovery_type in service_types
155155

156156
finally:

tests/test_asyncio.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,14 +919,16 @@ async def test_async_zeroconf_service_types(quick_timing: None) -> None:
919919
)
920920
task = await zeroconf_registrar.async_register_service(info)
921921
await task
922-
# Ensure we do not clear the cache until after the last broadcast is processed
923-
await asyncio.sleep(0.2)
922+
# Wait for the last announce broadcast before clearing. With
923+
# `quick_timing` the broadcasts use _REGISTER_TIME=10ms apart so
924+
# 50ms is plenty.
925+
await asyncio.sleep(0.05)
924926
_clear_cache(zeroconf_registrar.zeroconf)
925927
try:
926-
service_types = await AsyncZeroconfServiceTypes.async_find(interfaces=["127.0.0.1"], timeout=0.5)
928+
service_types = await AsyncZeroconfServiceTypes.async_find(interfaces=["127.0.0.1"], timeout=0.2)
927929
assert type_ in service_types
928930
_clear_cache(zeroconf_registrar.zeroconf)
929-
service_types = await AsyncZeroconfServiceTypes.async_find(aiozc=zeroconf_registrar, timeout=0.5)
931+
service_types = await AsyncZeroconfServiceTypes.async_find(aiozc=zeroconf_registrar, timeout=0.2)
930932
assert type_ in service_types
931933

932934
finally:

0 commit comments

Comments
 (0)