test: synchronise test_integration on browser first-query#1771
Conversation
After python-zeroconf#1760 shaved the probe random wait on loopback, async_register_service can finish faster than the ServiceBrowser fires its first startup query. The test asserts `len(answers[0]) == 0` (the initial outbound query carries no known PTR) — when the cache already holds the registered service by the time the first query is built, RFC 6762 §7.1 known-answer suppression makes that assertion racy. Wait for `got_query` once before calling `async_register_service` so the first startup query (built against an empty cache) is guaranteed to fire before the registration lands. Then clear the event and proceed.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1771 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 33 33
Lines 3536 3536
Branches 498 498
=======================================
Hits 3528 3528
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts tests/test_asyncio.py::test_integration to avoid a race where fast loopback registration can populate the cache before AsyncServiceBrowser emits its first startup query, which flips the test’s known-answer suppression assertion.
Changes:
- Waits for the browser’s first outbound startup query to be sent before registering the service.
- Clears the
got_queryevent immediately after that first query is observed to keep subsequent waits deterministic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Review — test: synchronise test_integration on browser first-queryMinimal, well-scoped test fix that pins the documented 🟢 Suggestions1. Comment is heavier than the change warrants (`tests/test_asyncio.py`, L1067-1072)Per the repo's CLAUDE.md ( Consider trimming to one line, e.g. # Barrier: first browser query must fire before the cache holds the
# PTR, or RFC 6762 §7.1 KAS makes answers[0] non-empty.
await asyncio.wait_for(got_query.wait(), 1)
got_query.clear()Not blocking — purely a style nudge against narrative comments. The change itself is correct and matches the documented Checklist
SummaryMinimal, well-scoped test fix that pins the documented Automated review by Kōan4fb1005 |
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
What
In
tests/test_asyncio.py::test_integration, wait for theServiceBrowser's first startup query to fire before registering the service.Why
#1760 shaved the loopback probe wait by patching
_PROBE_RANDOM_DELAY_INTERVALto (1, 5) inquick_timing. With that shave in place,async_register_servicecan finish faster than the browser's first startup query is built.The test later asserts
len(answers[0]) == 0— the first outbound query should carry no known PTR. When the registered service is already in the cache by the time that query is composed, RFC 6762 §7.1 known-answer suppression includes the PTR and the assertion flips.This is the one fragment of #1711 that isn't already merged via #1760. The old branch (
koan/speed-up-register-random-wait) had diverged too far for a clean rebase, so #1711 was closed in favour of this fresh PR.How
One
await asyncio.wait_for(got_query.wait(), 1)+got_query.clear()immediately beforeasync_register_service(info). Production code unchanged.Test plan
poetry run pytest tests/test_asyncio.py::test_integration -vpassespoetry run pytest --timeout=60 tests/passes (395 passed, 2 skipped)pre-commit(ruff, mypy, flake8, codespell, pyupgrade) passesCloses the open work from #1711.
Quality Report
Changes: 1 file changed, 6 insertions(+)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline