Skip to content

Commit

Permalink
testthreadingmock: Reduce chance of race condition
Browse files Browse the repository at this point in the history
Add longer delays to reduce the change of a race conditions on the tests
that validate short timeouts.
  • Loading branch information
mariocj89 committed Jul 3, 2023
1 parent cddd99d commit f3d8389
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Lib/test/test_unittest/testmock/testthreadingmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ def test_wait_failed_with_timeout_override(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, delay=0.1)
self.run_async(something.method_1, delay=0.5)
with self.assertRaises(AssertionError):
something.method_1.wait_until_called(timeout=0.05)
with self.assertRaises(AssertionError):
something.method_1.wait_until_any_call(timeout=0.05)

def test_wait_success_called_before(self):
waitable_mock = self._make_mock()
Expand All @@ -167,10 +165,10 @@ def test_wait_until_any_call_positional(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, 1, delay=0.1)
self.run_async(something.method_1, 2, delay=0.2)
self.run_async(something.method_1, 3, delay=0.3)
self.run_async(something.method_1, 1, delay=0.2)
self.assertNotIn(call(1), something.method_1.mock_calls)
self.run_async(something.method_1, 2, delay=0.5)
self.run_async(something.method_1, 3, delay=0.6)

something.method_1.wait_until_any_call(1)
something.method_1.assert_called_with(1)
Expand All @@ -186,10 +184,10 @@ def test_wait_until_any_call_keywords(self):

with patch(f"{__name__}.Something", waitable_mock):
something = Something()
self.run_async(something.method_1, a=1, delay=0.1)
self.run_async(something.method_1, b=2, delay=0.2)
self.run_async(something.method_1, c=3, delay=0.3)
self.run_async(something.method_1, a=1, delay=0.2)
self.assertNotIn(call(a=1), something.method_1.mock_calls)
self.run_async(something.method_1, b=2, delay=0.5)
self.run_async(something.method_1, c=3, delay=0.6)

something.method_1.wait_until_any_call(a=1)
something.method_1.assert_called_with(a=1)
Expand Down

0 comments on commit f3d8389

Please sign in to comment.