Skip to content

Commit 88ea850

Browse files
committed
demonstrate that the test fails on main
1 parent c865ab3 commit 88ea850

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_unittest/testmock/testthreadingmock.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
import unittest
3+
import threading
34
import concurrent.futures
45

56
from test.support import threading_helper
@@ -196,6 +197,22 @@ def test_reset_mock_resets_wait(self):
196197
m.wait_until_any_call_with()
197198
m.assert_called_once()
198199

200+
def test_call_count_thread_safe(self):
201+
m = ThreadingMock()
202+
# 3k loops reliably reproduces the issue while keeping runtime ~0.6s
203+
LOOPS = 3_000
204+
THREADS = 10
205+
def test_function():
206+
for _ in range(LOOPS):
207+
m()
208+
threads = [threading.Thread(target=test_function) for _ in range(THREADS)]
209+
for thread in threads:
210+
thread.start()
211+
for thread in threads:
212+
thread.join()
213+
214+
self.assertEqual(m.call_count, LOOPS * THREADS)
215+
199216

200217
if __name__ == "__main__":
201218
unittest.main()

0 commit comments

Comments
 (0)