Repository navigation
test: the near-duplicate scale test counts pairs, and the code-span growth test times longer calls (#916, #947) - #951
Conversation
…not seconds (intel#916) test_scale_of_5000_skills_is_a_few_seconds timed _near_duplicates with time.perf_counter() and asserted under 10 s, so a stalled or busy runner could fail it with no change in the code. A CPU-time ratio of growth() from 1250 to 5000 skills does not hold either: the pass takes 9.0 to 9.6 times as long at 5000 skills as at 1250 (limit 8), because the prefix filter cuts the pairs compared to about 2.3% of all pairs but does not make their number linear (18166 compared at 1250 skills, 283510 at 5000). The test now counts the pairs that reach the Jaccard check on the 5000-skill corpus and asserts fewer than 5% of all pairs (a brute-force pass compares about 90%), and that the near-copies are still found. Test-narrowed: test_scale_of_5000_skills_is_a_few_seconds is replaced by test_the_pass_compares_few_of_the_pairs_of_5000_skills, which asserts the work of the same pass on the same corpus instead of the seconds it took, and that the near-copies are found Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
… clock (intel#947) test_code_span_stripping_is_linear_on_backtick_runs failed once on CI with a growth ratio of 8.7 against the limit of 8. It was not reproduced on Linux in about 7,000 ratios, idle or with 64 parallel runs on 8 cores (3.0 to 3.6 for the backtick run, 3.9 to 4.5 for the other two shapes). The shortest sample, a run of 1000 backticks, is a call of about 10 µs, a few steps of the clock, so one hiccup moves its ratio a long way. The test now grows from 5000, so the shortest call lasts 50 µs and the others about 2 ms, and takes the best of 15 samples instead of 5. The limit is unchanged, and a quadratic scan still fails it. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #951 +/- ##
=======================================
Coverage 95.84% 95.84%
=======================================
Files 442 442
Lines 58843 58843
Branches 10148 10148
=======================================
+ Hits 56397 56401 +4
+ Misses 1521 1518 -3
+ Partials 925 924 -1 🚀 New features to boost your workflow:
|
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
LGTM
I checked 04b47c1. Both tests now measure something a slow runner does not change: the near-duplicate test counts _jaccard calls instead of seconds, and the code-span test times calls long enough for the clock.
Merge: safe now: it merges cleanly into current main, 1 commit behind. #958 also touches test_repo_budget.py but does not conflict with it.
What I ran, at 04b47c1:
make ci-local --offline: 0 failed, 25 passed, 20 skipped (network, matrix and other-platform jobs).
Checked, no issues
- The count is real:
_near_duplicatescalls_jaccardby its module-global name (validate.py:647), so the monkeypatch sees every compared pair. An all-pairs pass would compare 100% and fail the 5% bound, and the findings assertion stops a pass that compares nothing from passing. - Growth timing:
growth(..., 5_000, reps=15)matches the signature intests/growth_timing.py; the ratio bound is unchanged.
Summary
Two tests bounded work by something a slow runner changes.
maintodaytest_scale_of_5000_skills_is_a_few_secondstimes_near_duplicatesover 5000 skills withtime.perf_counter()and assertselapsed < 10.0, so a stalled runner fails it with no change in the code: withtime.perf_counterjumping 11 s between its two reads, the old body failsassert 11.0 < 10.0. The fix the issue suggests, a CPU-time ratio underGROWTH_LIMITfrom 1250 to 5000 skills, does not hold: over 12 runs the ratio is 9.04 to 9.58 (limit 8). The prefix filter keeps the pass from comparing every pair, but it is not linear: it reaches the Jaccard check for 18166 pairs at 1250 skills and 283510 at 5000, about 2.3% of all pairs at both sizes, so the count grows 15.6x for 4x the skills.test_code_span_stripping_is_linear_on_backtick_runsfailed once on CI with a ratio of 8.7 against 8. It does not fail here: about 7,000 ratios at n=1000, idle and with up to 64 parallel runs on 8 cores, are 3.0 to 3.6 for a run of backticks and 3.9 to 4.5 for the other two shapes. The cause on CI is not known. The shortest sample, a run of 1000 backticks, is a call of about 10 µs, a few steps of the clock, which is the most likely place for noise to move a ratio.For #916 the test now counts the pairs that reach
_jaccardon the 5000-skill corpus (a count does not change on a slow runner) and asserts fewer than 5% of all pairs, and that the near-copies are still found. The issue's other option, the absolute bound intime.process_time(), is not taken: it still pins an absolute number to the runner's speed. A pass over every pair compares 11,226,932 pairs (90%), so the bound has a margin of 2x over what the filter does today and 18x under brute force.For #947 the test grows from n=5000 instead of 1000, so the shortest call lasts 50 µs and the others about 2 ms, and takes the best of 15 samples instead of 5 (
reps=15). The limit stays 8. Counting work instead of time is not possible here:_strip_code_spansis linear in Python, but the regex backtracking it replaced runs inside the regex engine, where no count sees it. As the cause is not reproduced, this is a hardening; it is not shown to remove the flake.The pass is still quadratic in the pairs it compares, only with a constant of about 1/43. That is tracked in #950.
Closes #916
Closes #947
Changes
tests/test_near_duplicate_blocking.py:test_scale_of_5000_skills_is_a_few_secondsbecomestest_the_pass_compares_few_of_the_pairs_of_5000_skills; it patchesvalidate._jaccardto count calls, asserts under 5% of the pairs, and asserts findings exist. Thetimeimport and the timing print go. The dense-corpus equivalence tests are unchanged. The first commit carries aTest-narrowed:line, since the check reads a renamed test as removed. A second commit wraps the module docstring line the first one lengthened.tests/test_repo_budget.py:test_code_span_stripping_is_linear_on_backtick_runspasses5_000, reps=15togrowth(); the three behaviour asserts are unchanged.Risk
None for users: only tests change. A quadratic
_strip_code_spansnow takes minutes at n=5000, so it fails on the 60 s timeout in CI before it fails on the ratio (see Testing).Testing
On Linux, at
04b47c18(onmain2ab246c):make ci-local: 36 passed, 0 failed, 14 skipped (steps that need a tool or runner this machine lacks, such as semgrep, micromamba, the Python 3.11, 3.12 and 3.14 legs, and the PR-only jobs). 23691 tests passed, 19 skipped.time.perf_counterjumping 11 s per read, the old test body onmainfails (1 failed,assert 11.0 < 10.0); the new test under the same stalledperf_counterandprocess_timepasses (1 passed). The CPU-time ratio the issue suggested would have been 9.04 to 9.58 over 12 runs, above the limit of 8. Mutant:_near_duplicatesiterating every later skill instead of the candidates failsassert len(compared) < 0.05 * (5000 * 4999 // 2)with 11226932 compared.main's code the test passed in every run, so there is no failing run to show. Simulation of a busy runner (extra CPU time added togrowth()samples through itsclock=argument; a simulation, not a reproduction): one hit on one sample leaves the ratio at about 4.1 for both the old call (n=1000, 5 reps) and the new one (n=5000, 15 reps), since the best sample discards it; when each 4n sample is hit with probability 0.6 and each n sample with 0.15, 16 of 150 trials of the old call and 1 of 150 of the new one reach a ratio of 8. Mutant: a_strip_code_spansthat finds each run's closer with a scan of all later runs failsassert ratio < GROWTH_LIMITwith 16.5 when the timeout is off, and on the 60 spytest-timeoutunder the default settings.test/ctrl-c-eventsonmain2ab246c:pytest -n auto23691 passed, 19 skipped,mypyclean,ruff checkclean.Open questions
None.
Revert
A plain revert restores the two old tests. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)