test: scale aggregation timings 10x to speed up timing-dependent tests#1759
Merged
Conversation
`test_response_aggregation_timings` and `test_response_aggregation_timings_multiple` exercise the `MulticastOutgoingQueue` aggregation window, network protection (~1s), and protected aggregation. The behaviour under test is the ratio of these timings — not their absolute wall-clock values — so scaling the constants and the corresponding `asyncio.sleep`s down together preserves the test contract while dropping each test from ~3s to ~0.5s. Add `quick_aggregation_timing` to `tests/conftest.py` patching `zeroconf._core._AGGREGATION_DELAY` (500ms → 50ms), `_PROTECTED_AGGREGATION_DELAY` (200ms → 20ms), and `_ONE_SECOND` (1000ms → 100ms) before `MulticastOutgoingQueue` is constructed. Each test additionally pins its per-queue jitter (`_multicast_delay_random_min` / `_max`, exposed via `cdef public` in `multicast_outgoing_queue.pxd`) to 1-5ms so the scaled-down window is not dominated by the unscaled 20-120ms random delay. Net: ~5s saved per test run; sister tests still cover the same timing semantics. Closes the top two slowest entries on issue #1707. The remaining slow tests in #1707 (`test_get_info_suppressed_by_question_history`, `test_we_try_four_times_with_random_delay`) are dominated by `_DUPLICATE_QUESTION_INTERVAL = 999ms` which is `cdef`'d in `_services/info.pxd` and therefore unpatchable from Python under the Cython build; speeding those up is a separate refactor.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1759 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 33 33
Lines 3509 3509
Branches 493 493
=======================================
Hits 3501 3501
Misses 5 5
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Speeds up the top two entries on the slow-test list in #1707 by scaling the multicast aggregation / network-protection constants 10x in the timing tests, in lock-step with the corresponding test sleeps. Each test drops from ~3s to ~0.5s; ~5s saved per test-suite run.
Details
test_response_aggregation_timingsandtest_response_aggregation_timings_multipleexercise theMulticastOutgoingQueueaggregation window, network protection (~1s), and protected aggregation. The behaviour under test is the ratio of these timings (aggregation completes within window, protection blocks for the full second, protected aggregation collects within its window), not the absolute wall-clock values — so scaling them down together preserves the test contract.quick_aggregation_timingfixture intests/conftest.pypatcheszeroconf._core._AGGREGATION_DELAY(500ms → 50ms),_PROTECTED_AGGREGATION_DELAY(200ms → 20ms), and_ONE_SECOND(1000ms → 100ms). The patches must be in place beforeAsyncZeroconfis constructed sinceMulticastOutgoingQueuereads the constants at init time and stashes them on the instance._multicast_delay_random_min/_max, exposed viacdef publicinmulticast_outgoing_queue.pxd) to 1-5ms so the scaled-down window is not dominated by the unscaled 20-120ms random delay.asyncio.sleep(N)values are scaled in lock-step with the timing constants; comments now show the scaled arithmetic.Test plan
REQUIRE_CYTHON=1 poetry install --only=main,dev && poetry run pytest tests/test_handlers.py::test_response_aggregation_timings tests/test_handlers.py::test_response_aggregation_timings_multiple --no-cov --timeout=60: 2 passed in 1.14s (was ~6s combined).REQUIRE_CYTHON=1 ... poetry run pytest tests/ --no-cov --timeout=60: 384 passed, 3 skipped in 35.39s (was ~40s).SKIP_CYTHON=1 poetry run pytest tests/ --no-cov --timeout=60: 384 passed, 3 skipped in 35.44s.poetry run pre-commit runon touched files: ruff, ruff format, mypy, codespell, flake8 all green.Scope
This PR covers the top two slow tests on the list. The next two
(
test_get_info_suppressed_by_question_history,test_we_try_four_times_with_random_delay) are dominated by_DUPLICATE_QUESTION_INTERVAL = 999ms, which iscdef'd insrc/zeroconf/_services/info.pxdand therefore unpatchable from Python under the Cython build. Speeding those up needs either acdef-restructure or a virtual-clock approach, and is left as a separate refactor.