test: eliminate test_get_info_single race by injecting from the send mock#1716
Merged
Conversation
…mock `test_get_info_single` populated the cache via `_inject_response` (which hops through `run_coroutine_threadsafe`) after capturing the first query. Under `quick_request_timing` the request loop's next iteration fires ~15ms after iter 1's send, so on slow runners (PyPy + use_cython, observed on the PR #1710 CI matrix) iter 2's async_wait timer occasionally won the race against the inject — causing a second QM query to fire and the negative `last_sent is None` assertion to fail. Move the inject inside the `send` mock: when the first query goes out we synchronously call `record_manager.async_updates_from_response` on the same event-loop tick. By the time iter 1's call returns, the cache and ServiceInfo state already reflect the response — so `_is_complete` is True at iter 2's check and the loop exits without sending again. The test now asserts on the captured query list directly (one query, four questions) instead of polling with `send_event`. Runtime drops from ~0.11s to ~0.02s as a side-effect.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1716 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 33 33
Lines 3426 3426
Branches 471 471
=======================================
Hits 3418 3418
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
test_get_info_singlepopulated the cache via_inject_response(which hops throughrun_coroutine_threadsafe) after capturing the first query. Underquick_request_timingthe request loop's next iteration fires ~15ms after iter 1's send, so on slow runners (PyPy + use_cython, observed on the PR #1710 CI matrix) iter 2'sasync_waittimer occasionally won the race against the inject — causing a second QM query to fire and the negativelast_sent is Noneassertion to fail.Move the inject inside the
sendmock: when the first query goes out we synchronously callrecord_manager.async_updates_from_responseon the same event-loop tick. By the time iter 1's call returns, the cache andServiceInfostate already reflect the response — so_is_completeis True at iter 2's check and the loop exits without sending again.The test now asserts on the captured query list directly (one query, four questions) instead of polling with
send_event. Runtime drops from ~0.11s to ~0.02s as a side-effect.Test plan
tests/suite passes (337 passed, 3 IPv6 skips)