Skip to content

test: eliminate test_get_info_single race by injecting from the send mock#1716

Merged
bdraco merged 1 commit into
masterfrom
fix/test-get-info-single-race
May 18, 2026
Merged

test: eliminate test_get_info_single race by injecting from the send mock#1716
bdraco merged 1 commit into
masterfrom
fix/test-get-info-single-race

Conversation

@bdraco

@bdraco bdraco commented May 18, 2026

Copy link
Copy Markdown
Member

Summary

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.

Test plan

  • Targeted test passes (Cython build)
  • Targeted test stable across 5 sequential runs
  • Full tests/ suite passes (337 passed, 3 IPv6 skips)
  • Pre-commit hooks pass

…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.
@codspeed-hq

codspeed-hq Bot commented May 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing fix/test-get-info-single-race (a01ad1a) with master (91aa21d)

Open in CodSpeed

@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (91aa21d) to head (a01ad1a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bdraco bdraco merged commit 963d3d7 into master May 18, 2026
37 checks passed
@bdraco bdraco deleted the fix/test-get-info-single-race branch May 18, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant