gh-106458: Mark testthreadingmock.py with @requires_working_threading (GH-106366)

Mark `testthreadingmock.py` with `threading_helper.requires_working_threading`.

Also add longer delays to reduce the change of a race conditions on the tests that validate short timeouts.
This commit is contained in:
Mario Corchero 2023-07-06 19:54:45 +02:00 committed by GitHub
parent e7cd55753b
commit 56353b1002
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,9 +2,13 @@ import time
import unittest
import concurrent.futures
from test.support import threading_helper
from unittest.mock import patch, ThreadingMock, call
threading_helper.requires_working_threading(module=True)
class Something:
def method_1(self):
pass
@ -133,11 +137,9 @@ class TestThreadingMock(unittest.TestCase):
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_with(timeout=0.05)
def test_wait_success_called_before(self):
waitable_mock = self._make_mock()
@ -163,10 +165,10 @@ class TestThreadingMock(unittest.TestCase):
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_with(1)
something.method_1.assert_called_with(1)
@ -182,10 +184,10 @@ class TestThreadingMock(unittest.TestCase):
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_with(a=1)
something.method_1.assert_called_with(a=1)