Commit 92523c3
fix: fix thread-safety crash in Matcher when tests run in parallel
The `Matcher` singleton's `matchers` array is accessed without
synchronization. Under Swift Testing's parallel execution, concurrent
`register()` writes and `comparator()` reads from multiple test
`init()` methods cause data races that crash the test process.
Observed crash sites:
- `Matcher.register<A>(_:)` — concurrent appends to the array
- `closure #1 in Parameter.eraseToGenericValue()` — concurrent reads
via `Matcher.comparator(for:)` while another thread appends
Add an NSLock to synchronize all matchers array access. The lock is
applied at the leaf level (append and snapshot-read) to avoid
re-entrancy in the Sequence comparator path which calls
`comparator(by:)` → `comparator(for: T.Element.self)` →
`comparator(by:)`.1 parent e969f84 commit 92523c3
1 file changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| |||
0 commit comments