Skip to content

Commit 6c48ed7

Browse files
authored
gh-130736: Fix asyncio test_shutdown_default_executor_timeout() (#130800)
Replace time.sleep() with threading.Event.
1 parent 3929af5 commit 6c48ed7

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
@@ -233,20 +233,25 @@ def test_set_default_executor_error(self):
233233
self.assertIsNone(self.loop._default_executor)
234234

235235
def test_shutdown_default_executor_timeout(self):
236+
event = threading.Event()
237+
236238
class DummyExecutor(concurrent.futures.ThreadPoolExecutor):
237239
def shutdown(self, wait=True, *, cancel_futures=False):
238240
if wait:
239-
time.sleep(0.1)
241+
event.wait()
240242

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

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

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

0 commit comments

Comments
 (0)