mirror of
https://github.com/python/cpython.git
synced 2026-06-28 03:41:13 +00:00
[3.15] gh-150175: Fix ThreadingMock call_count race condition (GH-150176) (#150182)
gh-150175: Fix ThreadingMock call_count race condition (GH-150176)
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.
(cherry picked from commit 388e023fe1)
Co-authored-by: saisneha196 <156835592+saisneha196@users.noreply.github.com>
This commit is contained in:
parent
79e17d7fa5
commit
528356eac0
2 changed files with 7 additions and 0 deletions
|
|
@ -3121,6 +3121,10 @@ def _mock_call(self, *args, **kwargs):
|
|||
|
||||
return ret_value
|
||||
|
||||
def _increment_mock_call(self, /, *args, **kwargs):
|
||||
with self._mock_calls_events_lock:
|
||||
super()._increment_mock_call(*args, **kwargs)
|
||||
|
||||
def wait_until_called(self, *, timeout=_timeout_unset):
|
||||
"""Wait until the mock object is called.
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Fix race condition in :class:`unittest.mock.ThreadingMock` where
|
||||
concurrent calls could lose increments to ``call_count`` and other
|
||||
attributes due to a missing lock in ``_increment_mock_call``.
|
||||
Loading…
Add table
Add a link
Reference in a new issue