File tree Expand file tree Collapse file tree 1 file changed +3
-27
lines changed
Lib/test/test_unittest/testmock Expand file tree Collapse file tree 1 file changed +3
-27
lines changed Original file line number Diff line number Diff line change @@ -198,38 +198,14 @@ def test_reset_mock_resets_wait(self):
198198 m .wait_until_any_call_with ()
199199 m .assert_called_once ()
200200
201-
202- class TestThreadingMockRaceCondition (unittest .TestCase ):
203- """Test that exposes race conditions in ThreadingMock."""
204-
205- def setUp (self ):
206- self ._executor = concurrent .futures .ThreadPoolExecutor (max_workers = 5 )
207- self .addCleanup (self ._executor .shutdown )
208-
209- # Store and restore original switch interval using addCleanup
210- self .addCleanup (sys .setswitchinterval , sys .getswitchinterval ())
211-
212- # Set switch interval to minimum to force frequent context switches
213- sys .setswitchinterval (sys .float_info .min )
214-
215- def test_call_count_race_condition_with_fast_switching (self ):
216- """Force race condition by maximizing thread context switches.
217-
218- This test reduces the thread switch interval to its minimum value,
219- which maximizes the likelihood of context switches during the critical
220- section of _increment_mock_call.
221- """
201+ def test_call_count_thread_safe (self ):
222202 m = ThreadingMock ()
223-
224- # Use fewer loops but with maximum context switching pressure
225- # Expected runtime is 0.2 second
226- LOOPS = 100
203+ # 3k loops reliably reproduces the issue while keeping runtime ~0.6s
204+ LOOPS = 3_000
227205 THREADS = 10
228-
229206 def test_function ():
230207 for _ in range (LOOPS ):
231208 m ()
232-
233209 threads = [threading .Thread (target = test_function ) for _ in range (THREADS )]
234210 for thread in threads :
235211 thread .start ()
You can’t perform that action at this time.
0 commit comments