Repository navigation
Commit 730e5eb
committed
Make CollectionRetriever most_popular fixtures deterministic
Fixes #903.
`object_ids.sample(5)` across five check-ins left both the occurrence counts
and the `$limit 10` cut-off to chance, so
"makes occurrences counts available after retrieve" failed intermittently:
Failure/Error: expect(min_occurrence).to be < max_occurrence
expected: < 2
got: 2
25 random draws over 20 objects regularly leaves the ten highest-counted
objects tied, and CollectionRetriever#most_popular caps `occurrences` at ten,
so min == max and the strict comparison fails. Measured at 5 failures in 500
runs on master.
Replaced the random sample with nested slices, which give every object a
known count:
5 5 | 4 4 4 | 3 3 3 3 3 || 2 2 2 2 2 | 1 1 1 1 1
That fixes two separate sources of nondeterminism, not just the visible one.
The top ten now have a real spread (5 down to 3), and the tenth and eleventh
differ (3 vs 2), so the `$limit 10` never has to break a tie at the cut-off --
which would otherwise make *which* objects come back arbitrary and could flake
"retrieves the most popular" the same way.
Since the counts are now known, the weak `min < max` assertion is replaced
with the exact sequence. This tests strictly more: it covers the descending
sort and the counts themselves rather than just the existence of a spread.
Which objects tie at a given count is still undefined -- the aggregation sorts
on count alone -- so the assertion is on counts only.
The sibling assertions still hold and are now deterministic too: the objects
outside the top ten have counts 2 and 1 against a minimum of 3, and all twenty
objects are global, so "limits results to 10" always finds ten.
Verified: 0 failures in 300 runs, against 5 in 500 on master. Full suite
green (320 examples), standardrb clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent ffc6505 commit 730e5eb
1 file changed
Lines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | | - | |
29 | | - | |
| 38 | + | |
| 39 | + | |
30 | 40 | | |
31 | 41 | | |
32 | 42 | | |
| |||
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
| |||
0 commit comments