Commit 74d4ed7
Fix flaky TestHash#test_rehash by modelling the AR substitution hint
test_rehash mutates a key until its own `hash_hint` (the low byte of
`Array#hash`) changes, then asserts the stale key no longer hits.
Since 127e903 "hash.c: add a substition hint", `ar_do_hash_hint()`
maps RHASH_AR_CLEARED_HINT (0x00) to RHASH_AR_SUBSTITUTION_HINT (0x01),
so hash values ending in 0x00 and 0x01 share a hint. When the mutation
loop happened to exit on such a pair, the test believed the hint had
changed while the AR table's hint had not: `ar_find_entry_hint()` still
matched and `ar_equal()` compared the key against itself, so the lookup
returned 100 instead of nil.
That commit adjusted the affected specs but not test/ruby/test_hash.rb.
Mirror the substitution in `hash_hint` so the loop keeps going until the
hint really changes.
The hash seed is per process, so this depended on the run; measured over
2,000,000 independent starting hashes the old loop failed 63 times
(1/31746), matching the predicted (2/256) * (1/255). Both TestHash and
TestHash::TestSubHash fail together because they share a process and
build the same strings.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 81ab701 commit 74d4ed7
1 file changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
621 | 624 | | |
622 | 625 | | |
623 | 626 | | |
| |||
0 commit comments