Commit fb6fdb7
Fix per-process randomized string hashing in test-framework codec/similarity selection
MockRandomPostingsFormat, RandomCodec, and RandomSimilarityProvider chose a
per-file/per-field int-stream factory, postings/docvalues format, and similarity
by indexing into a collection with `string.GetHashCode()`. On .NET, string hash
codes are randomized per process, so a choice made when writing an index (e.g. in
the forked child process of TestIndexWriterOnJRECrash) differed from the choice
made when reading it back in another process, producing spurious "codec header
mismatch" / CheckIndex failures. Java is unaffected because String.hashCode() is
deterministic across JVMs.
Use J2N's CharSequenceComparer.Ordinal.GetHashCode(), which is deterministic and
produces the same value as Java's String.hashCode(), keeping writer and reader in
sync. This was a pre-existing test-framework bug (reproduces on master).
Verified: TestIndexWriterOnJRECrash.TestNRTThreads_Mem (previously a deterministic
failure under seed 0x03c0703dd1d74190:0xfc8ded704ed908f9) now passes on fixed and
random seeds; RandomCodec- and similarity-heavy suites remain green. Confirmed
against a native build of upstream Lucene 4.8.1, which passes this test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent b403674 commit fb6fdb7
3 files changed
Lines changed: 27 additions & 7 deletions
File tree
- src/Lucene.Net.TestFramework
- Codecs/MockRandom
- Index
- Search
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
| |||
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
110 | | - | |
| 116 | + | |
| 117 | + | |
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
91 | | - | |
| 97 | + | |
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
| |||
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
110 | | - | |
| 116 | + | |
| 117 | + | |
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
114 | | - | |
| 121 | + | |
115 | 122 | | |
116 | 123 | | |
117 | 124 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| |||
0 commit comments