Skip to content

test: speed up service-info request tests with quick_request_timing fixture#1709

Merged
bdraco merged 2 commits into
masterfrom
perf/tests-quick-request-timing
May 18, 2026
Merged

test: speed up service-info request tests with quick_request_timing fixture#1709
bdraco merged 2 commits into
masterfrom
perf/tests-quick-request-timing

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 17, 2026

Summary

Part of #1707 (slow tests sweep). Bucket B of a 3-PR series (follows #1708).

AsyncServiceInfo.async_request waits _LISTENER_TIME (200ms) plus 20-120ms of jitter before firing the first query — RFC 6762 §5.2 spread-out behavior for real networks. On loopback that's pure overhead. Tests that only need to see which queries get sent paid the wait every time and had to pad their timeouts to ~500ms to accommodate it.

New quick_request_timing fixture in tests/conftest.py patches _LISTENER_TIME=10 and _AVOID_SYNC_DELAY_RANDOM_INTERVAL=(1, 5). With the fixture, callers can drop their timeouts and negative-wait windows to ~50-100ms.

Speedups:

test before after
test_get_info_single 1.01s 0.11s
test_info_asking_default_is_asking_qm_questions_after_the_first_qu 0.77s 0.30s
test_asking_qu_questions 0.52s 0.05s
test_asking_qm_questions (symmetric — picked up for consistency) similar 0.05s

No production change — both constants were already plain Python module attributes on _services.info (not declared in info.pxd), so the patches take effect under both the Cython and pure-Python builds.

Test plan

  • Targeted tests pass under Cython build
  • Full tests/ suite passes (337 passed, 3 IPv6 skips)
  • Pre-commit hooks pass

…ixture

`AsyncServiceInfo.async_request` waits `_LISTENER_TIME` (200ms) plus
20-120ms of jitter before firing the first query. On real networks
that staggering helps clients avoid synchronized bursts (RFC 6762
§5.2); on loopback it's pure overhead. Tests that only need to see
which queries get sent paid the wait every time and had to pad their
timeouts to ~500ms to accommodate it.

New `quick_request_timing` fixture patches `_LISTENER_TIME=10` and
the jitter interval to `(1, 5)`. With the fixture, callers can drop
their timeouts and negative-wait windows to ~50-100ms.

Speedups:
- test_get_info_single: 1.01s → 0.11s
- test_info_asking_default_is_asking_qm_questions_after_the_first_qu:
  0.77s → 0.30s
- test_asking_qu_questions: 0.52s → 0.05s
- test_asking_qm_questions: similar, also picks up the fixture for
  symmetry with test_asking_qu_questions.

No production change — both constants were already plain Python
module attributes on `_services.info` (not declared in `info.pxd`),
so the patches take effect under both the Cython and pure-Python
builds.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing perf/tests-quick-request-timing (a662920) with master (ee3c7d7)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (0deb56b) to head (a662920).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1709   +/-   ##
=======================================
  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.

…UT_MS)

The 50ms get_service_info / async_request timeout used by the three
tests that opt in to `quick_request_timing` was a bare integer
literal. Hoist it to a `QUICK_REQUEST_TIMEOUT_MS` constant in
`tests/__init__.py` so the relationship to the fixture (which
shortens the initial-query delay to ~15ms) is documented and the
value lives in one place.
@bdraco bdraco merged commit 4bae30a into master May 18, 2026
34 of 35 checks passed
@bdraco bdraco deleted the perf/tests-quick-request-timing branch May 18, 2026 00:21
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