Commit 86a9b99
Implement IsTestThread to fix flaky TestFlushExceptions
LuceneTestCase.IsTestThread was hardcoded to always return true, so the
flush-failure injection in TestConcurrentMergeScheduler.TestFlushExceptions
fired on background ConcurrentMergeScheduler merge threads (which also flush
via CompressingStoredFieldsWriter.Flush()), not just the test thread. When a
merge thread happened to be flushing during the SetDoFail()/Flush() window and
Random.NextBoolean() returned true, the merge threw, surfacing as a flaky
MergeException at teardown.
Capture the test-case thread in SetUp() (cleared in TearDown()) in a
[ThreadStatic] field and have IsTestThread compare against it, mirroring Java's
ThreadAndTestNameRule.testCaseThread. Tests run with LevelOfParallelism(1), and
NUnit's TimeoutCommand (active via the assembly-wide [Timeout]) runs SetUp, the
test body, and TearDown on the same thread, so the capture lines up with the
thread executing the test method. Background merge threads never run SetUp, so
they correctly see a null test thread and are excluded.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 3dbdaef commit 86a9b99
1 file changed
Lines changed: 23 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
899 | 904 | | |
900 | 905 | | |
901 | 906 | | |
| |||
983 | 988 | | |
984 | 989 | | |
985 | 990 | | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
986 | 996 | | |
987 | 997 | | |
988 | 998 | | |
| |||
1147 | 1157 | | |
1148 | 1158 | | |
1149 | 1159 | | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
1150 | 1170 | | |
1151 | 1171 | | |
1152 | 1172 | | |
1153 | | - | |
1154 | | - | |
1155 | 1173 | | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1159 | 1177 | | |
1160 | 1178 | | |
1161 | 1179 | | |
| |||
0 commit comments