Commit ba116c3
committed
Fix ThreadingMock call_count race condition
ThreadingMock._increment_mock_call() was not thread-safe.
Multiple threads calling the mock simultaneously could lose
increments due to race conditions on call_count and other
attributes.
Fix by overriding _increment_mock_call in ThreadingMixin
and wrapping it with the existing _mock_calls_events_lock.
Reproducer:
m = unittest.mock.ThreadingMock()
# Run 50 threads each calling m() 10000 times
# Expected: 500000, Got: ~460000 (missing calls)1 parent cb3b4b9 commit ba116c3
1 file changed
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3113 | 3113 | | |
3114 | 3114 | | |
3115 | 3115 | | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
3116 | 3120 | | |
3117 | 3121 | | |
3118 | 3122 | | |
| |||
0 commit comments