test: speed up slow loopback tests (closes #1697)#1699
Draft
bluetoothbot wants to merge 1 commit into
Draft
Conversation
…er timeouts Cuts ~28s from the top-20 durations sum (was 70s, now 42s) without changing what the tests assert. - Add quick_timing fixture (introduced for the same purpose in conftest) to register/announce-heavy tests in test_asyncio.py, test_services.py, test_handlers.py, and test_init.py. The fixture shortens _CHECK_TIME/_REGISTER_TIME/_UNREGISTER_TIME to 10ms on loopback so the probe/announce/goodbye cycle no longer pays the RFC 6762 production budget. - Drop ZeroconfServiceTypes.find timeouts from 2s to 0.5s in test_types.py and test_async_zeroconf_service_types — find() sleeps the full timeout, and on loopback the response arrives in milliseconds. - Tighten the explicit TOCTOU wait in test_service_info_async_request from 3000ms to 500ms; _is_complete=False forces the request to run out the full timeout regardless. - Cut the 'allow multicast timers to expire' sleep in test_integration_with_listener_class from 3s to 0.5s now that quick_timing makes the preceding broadcasts settle in <100ms. - Shorten the duplicate-update negative-assertion wait in TestServiceBrowser.test_update_record from wait_time=3 to 0.3s — the listener is asserted NOT to fire, so the wait always times out.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1699 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 33 33
Lines 3410 3410
Branches 464 464
=======================================
Hits 3402 3402
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.
What
Cut ~28s from the slowest-20 duration sum (70s → 42s) without changing
what any test asserts. All 336 tests still pass.
Why
Issue #1697 — the slow-test report listed twenty tests taking 2–10s
each, dominated by full mDNS probe/announce/goodbye cycles on
loopback. The project already ships a
quick_timingfixture intests/conftest.pyfor this exact case (RFC 6762 timings don't needto apply when talking to 127.0.0.1) — it just wasn't applied
everywhere.
How
quick_timingto register/announce-heavy tests intests/test_asyncio.py,tests/test_services.py,tests/test_handlers.py, andtests/test_init.py. Forunittest.TestCase-based tests, wired in via@pytest.mark.usefixtures("quick_timing").ZeroconfServiceTypes.findtimeouts from 2s to 0.5s intests/services/test_types.pyandtest_async_zeroconf_service_types—
find()sleeps the full timeout, and on loopback the responsearrives in milliseconds.
test_service_info_async_requestfrom 3000ms to 500ms;_is_complete=Falseforces the request to run out the full timeoutregardless of network latency.
test_integration_with_listener_classfrom 3s to 0.5s now thatquick_timingmakes the preceding broadcasts settle in <100ms.TestServiceBrowser.test_update_recordfromwait_time=3to 0.3s— the listener is asserted NOT to fire, so the wait always times
out.
Tests left untouched include
test_async_updates_from_response(needs the RFC 6762 §10.2 one-second invalidation window),
test_get_info_suppressed_by_question_history,test_we_try_four_times_with_random_delay, and thetest_response_aggregation_timings*pair — those measure timingbehaviour and the real delays are the assertion.
Testing
poetry run pytest --durations=20 --timeout=60— 336 passed,2 skipped, 83.5s (was 87.4s)
drop on
--durations.ruff check+ruff format --checkclean.Per-test before/after on the slowest entries from #1697:
test_service_info_async_requesttest_integration_with_listener_classtest_async_zeroconf_service_typestest_integration_with_listenertest_integration_with_listener_v6_recordstest_integration_with_subtype_and_listenertest_update_record(browser)test_register_and_lookup_type_by_uppercase_nametest_async_service_registrationtest_verify_name_change_with_lots_of_namestest_async_service_browsertest_async_taskstest_async_service_registration_with_server_missingtest_async_service_registration_name_conflicttest_name_conflictsCloses #1697
Quality Report
Changes: 6 files changed, 27 insertions(+), 19 deletions(-)
Code scan: clean
Tests: passed (4 PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline