Skip to content

Commit f3d8389

Browse files
committed
testthreadingmock: Reduce chance of race condition
Add longer delays to reduce the change of a race conditions on the tests that validate short timeouts.
1 parent cddd99d commit f3d8389

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Lib/test/test_unittest/testmock/testthreadingmock.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ def test_wait_failed_with_timeout_override(self):
137137

138138
with patch(f"{__name__}.Something", waitable_mock):
139139
something = Something()
140-
self.run_async(something.method_1, delay=0.1)
140+
self.run_async(something.method_1, delay=0.5)
141141
with self.assertRaises(AssertionError):
142142
something.method_1.wait_until_called(timeout=0.05)
143-
with self.assertRaises(AssertionError):
144-
something.method_1.wait_until_any_call(timeout=0.05)
145143

146144
def test_wait_success_called_before(self):
147145
waitable_mock = self._make_mock()
@@ -167,10 +165,10 @@ def test_wait_until_any_call_positional(self):
167165

168166
with patch(f"{__name__}.Something", waitable_mock):
169167
something = Something()
170-
self.run_async(something.method_1, 1, delay=0.1)
171-
self.run_async(something.method_1, 2, delay=0.2)
172-
self.run_async(something.method_1, 3, delay=0.3)
168+
self.run_async(something.method_1, 1, delay=0.2)
173169
self.assertNotIn(call(1), something.method_1.mock_calls)
170+
self.run_async(something.method_1, 2, delay=0.5)
171+
self.run_async(something.method_1, 3, delay=0.6)
174172

175173
something.method_1.wait_until_any_call(1)
176174
something.method_1.assert_called_with(1)
@@ -186,10 +184,10 @@ def test_wait_until_any_call_keywords(self):
186184

187185
with patch(f"{__name__}.Something", waitable_mock):
188186
something = Something()
189-
self.run_async(something.method_1, a=1, delay=0.1)
190-
self.run_async(something.method_1, b=2, delay=0.2)
191-
self.run_async(something.method_1, c=3, delay=0.3)
187+
self.run_async(something.method_1, a=1, delay=0.2)
192188
self.assertNotIn(call(a=1), something.method_1.mock_calls)
189+
self.run_async(something.method_1, b=2, delay=0.5)
190+
self.run_async(something.method_1, c=3, delay=0.6)
193191

194192
something.method_1.wait_until_any_call(a=1)
195193
something.method_1.assert_called_with(a=1)

0 commit comments

Comments
 (0)