Skip to content

Commit a30eb88

Browse files
committed
test: apply review feedback on shutdown-loop race and fixture docs
1 parent 038579d commit a30eb88

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/zeroconf/_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@
106106

107107
# RFC 6762 §8.1 thundering-herd avoidance: wait a random
108108
# 0-250ms before the first probe so simultaneously-started
109-
# responders don't collide. The repo enforces a 150ms floor
110-
# to keep the existing test deadlines comfortable; tests on
111-
# loopback can patch this down via the `quick_timing` fixture.
109+
# responders don't collide. We default to 150-250ms to
110+
# preserve existing timing assumptions; tests on loopback
111+
# may patch this lower via the `quick_timing` fixture.
112112
_PROBE_RANDOM_DELAY_INTERVAL = (150, 250) # ms
113113

114114

tests/conftest.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def quick_timing() -> Generator[None]:
8888
probing, §5.2 for the initial-query delay). Tests on 127.0.0.1
8989
do not need them and pay 1-2s per register/unregister cycle,
9090
150-250ms per probe, and 20-120ms per ServiceBrowser startup
91-
without this fixture. Opt in by adding `quick_timing` to a
92-
test's argument list.
91+
without this fixture. Opt in either by adding `quick_timing`
92+
to a test's argument list or via
93+
`@pytest.mark.usefixtures("quick_timing")` on the test or
94+
its class.
9395
"""
9496
with (
9597
patch.object(_core, "_CHECK_TIME", 10),
@@ -108,9 +110,11 @@ def quick_request_timing() -> Generator[None]:
108110
The 200ms `_LISTENER_TIME` and 20-120ms random jitter (RFC 6762
109111
§5.2) help spread queries from multiple clients on real networks.
110112
On loopback they're pure overhead — get_service_info-style tests
111-
wait ~250ms before the first query even fires. Opt in by adding
112-
`quick_request_timing` to a test's argument list, then drop the
113-
test's own timeouts (which had to accommodate that delay).
113+
wait ~250ms before the first query even fires. Opt in either by
114+
adding `quick_request_timing` to a test's argument list or via
115+
`@pytest.mark.usefixtures("quick_request_timing")` on the test
116+
or its class, then drop the test's own timeouts (which had to
117+
accommodate that delay).
114118
"""
115119
with (
116120
patch.object(service_info, "_LISTENER_TIME", 10),

tests/utils/test_asyncio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ async def _still_running():
8686
await asyncio.sleep(5)
8787

8888
def _run_coro() -> None:
89-
runcoro_thread_ready.set()
9089
assert loop is not None
90+
future = asyncio.run_coroutine_threadsafe(_still_running(), loop)
91+
runcoro_thread_ready.set()
9192
with contextlib.suppress(concurrent.futures.TimeoutError):
92-
asyncio.run_coroutine_threadsafe(_still_running(), loop).result(0.1)
93+
future.result(0.1)
9394

9495
runcoro_thread = threading.Thread(target=_run_coro, daemon=True)
9596
runcoro_thread.start()
9697
runcoro_thread_ready.wait()
9798

98-
time.sleep(0.05)
9999
assert loop is not None
100100
# Patch _TASK_AWAIT_TIMEOUT so the inner `asyncio.wait` returns
101-
# immediately instead of blocking the full 1s on the deliberately
101+
# within 50ms instead of blocking the full 1s on the deliberately
102102
# never-completing _still_running() task.
103103
with patch.object(aioutils, "_TASK_AWAIT_TIMEOUT", 0.05):
104104
aioutils.shutdown_loop(loop)

0 commit comments

Comments
 (0)