From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 4 Mar 2025 12:11:00 +0000 (+0100) Subject: [3.12] gh-130736: Fix asyncio test_shutdown_default_executor_timeout() (GH-130800... X-Git-Tag: v3.12.10~128 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a0ac4dbe88041c7ca1d58c85305bf9d8c2286c19;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-130736: Fix asyncio test_shutdown_default_executor_timeout() (GH-130800) (#130826) gh-130736: Fix asyncio test_shutdown_default_executor_timeout() (GH-130800) Replace time.sleep() with threading.Event. (cherry picked from commit 6c48ed7d62c6ca0eb24935b0e612f9e4a1a3b1bc) Co-authored-by: Victor Stinner --- diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index f3abe7aa9d4e..f5cdfc4e431d 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -232,20 +232,25 @@ class BaseEventLoopTests(test_utils.TestCase): self.assertIsNone(self.loop._default_executor) def test_shutdown_default_executor_timeout(self): + event = threading.Event() + class DummyExecutor(concurrent.futures.ThreadPoolExecutor): def shutdown(self, wait=True, *, cancel_futures=False): if wait: - time.sleep(0.1) + event.wait() self.loop._process_events = mock.Mock() self.loop._write_to_self = mock.Mock() executor = DummyExecutor() self.loop.set_default_executor(executor) - with self.assertWarnsRegex(RuntimeWarning, - "The executor did not finishing joining"): - self.loop.run_until_complete( - self.loop.shutdown_default_executor(timeout=0.01)) + try: + with self.assertWarnsRegex(RuntimeWarning, + "The executor did not finishing joining"): + self.loop.run_until_complete( + self.loop.shutdown_default_executor(timeout=0.01)) + finally: + event.set() def test_call_soon(self): def cb():