Skip to content

Commit a0ac4db

Browse files
[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 6c48ed7) Co-authored-by: Victor Stinner <[email protected]>
1 parent 7ce5f15 commit a0ac4db

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Lib/test/test_asyncio/test_base_events.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,25 @@ def test_set_default_executor_error(self):
232232
self.assertIsNone(self.loop._default_executor)
233233

234234
def test_shutdown_default_executor_timeout(self):
235+
event = threading.Event()
236+
235237
class DummyExecutor(concurrent.futures.ThreadPoolExecutor):
236238
def shutdown(self, wait=True, *, cancel_futures=False):
237239
if wait:
238-
time.sleep(0.1)
240+
event.wait()
239241

240242
self.loop._process_events = mock.Mock()
241243
self.loop._write_to_self = mock.Mock()
242244
executor = DummyExecutor()
243245
self.loop.set_default_executor(executor)
244246

245-
with self.assertWarnsRegex(RuntimeWarning,
246-
"The executor did not finishing joining"):
247-
self.loop.run_until_complete(
248-
self.loop.shutdown_default_executor(timeout=0.01))
247+
try:
248+
with self.assertWarnsRegex(RuntimeWarning,
249+
"The executor did not finishing joining"):
250+
self.loop.run_until_complete(
251+
self.loop.shutdown_default_executor(timeout=0.01))
252+
finally:
253+
event.set()
249254

250255
def test_call_soon(self):
251256
def cb():

0 commit comments

Comments
 (0)