Skip to content

Commit a7b4f8e

Browse files
authored
Fix reliablity of tests that patch sending (#820)
1 parent f9d3529 commit a7b4f8e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎tests/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ async def _wait_for_response():
4141
asyncio.run_coroutine_threadsafe(_wait_for_response(), zc.loop).result()
4242

4343

44+
def _wait_for_start(zc: Zeroconf) -> None:
45+
"""Wait for all sockets to be up and running."""
46+
assert zc.loop is not None
47+
asyncio.run_coroutine_threadsafe(zc.async_wait_for_start(), zc.loop).result()
48+
49+
4450
@lru_cache(maxsize=None)
4551
def has_working_ipv6():
4652
"""Return True if if the system can bind an IPv6 address."""

‎tests/services/test_browser.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from zeroconf._services.info import ServiceInfo
2323
from zeroconf.aio import AsyncZeroconf
2424

25-
from .. import has_working_ipv6, _inject_response
25+
from .. import has_working_ipv6, _inject_response, _wait_for_start
2626

2727

2828
log = logging.getLogger('zeroconf')
@@ -435,6 +435,7 @@ def test_backoff(suppresses_mock):
435435

436436
type_ = "_http._tcp.local."
437437
zeroconf_browser = Zeroconf(interfaces=['127.0.0.1'])
438+
_wait_for_start(zeroconf_browser)
438439

439440
# we are going to patch the zeroconf send to check query transmission
440441
old_send = zeroconf_browser.async_send
@@ -513,6 +514,7 @@ def test_first_query_delay():
513514
"""
514515
type_ = "_http._tcp.local."
515516
zeroconf_browser = Zeroconf(interfaces=['127.0.0.1'])
517+
_wait_for_start(zeroconf_browser)
516518

517519
# we are going to patch the zeroconf send to check query transmission
518520
old_send = zeroconf_browser.async_send
@@ -666,6 +668,7 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
666668
service_removed.set()
667669

668670
zeroconf_browser = Zeroconf(interfaces=['127.0.0.1'])
671+
_wait_for_start(zeroconf_browser)
669672

670673
# we are going to patch the zeroconf send to check packet sizes
671674
old_send = zeroconf_browser.async_send

0 commit comments

Comments
 (0)