[Python-checkins] [3.11] gh-99357: Close the event loop when it is no longer used in test_uncancel_structured_blocks (GH-99414) (#99424)
gvanrossum
webhook-mailer at python.org
Mon Nov 14 13:52:16 EST 2022
https://github.com/python/cpython/commit/90de4b76b9ef557710419fcc0d11ce90b18ac05c
commit: 90de4b76b9ef557710419fcc0d11ce90b18ac05c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-11-14T10:52:10-08:00
summary:
[3.11] gh-99357: Close the event loop when it is no longer used in test_uncancel_structured_blocks (GH-99414) (#99424)
(cherry picked from commit 99972dc7450f1266e39202012827f4f3c995b0ca)
Co-authored-by: Xiao Chen <chenxiao_7 at 163.com>
files:
M Lib/test/test_asyncio/test_tasks.py
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 7585768073e6..6b875cfb4dcb 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -639,27 +639,30 @@ def on_timeout():
await asyncio.sleep(0)
return timed_out, structured_block_finished, outer_code_reached
- # Test which timed out.
- t1 = self.new_task(loop, make_request_with_timeout(sleep=10.0, timeout=0.1))
- timed_out, structured_block_finished, outer_code_reached = (
- loop.run_until_complete(t1)
- )
- self.assertTrue(timed_out)
- self.assertFalse(structured_block_finished) # it was cancelled
- self.assertTrue(outer_code_reached) # task got uncancelled after leaving
- # the structured block and continued until
- # completion
- self.assertEqual(t1.cancelling(), 0) # no pending cancellation of the outer task
-
- # Test which did not time out.
- t2 = self.new_task(loop, make_request_with_timeout(sleep=0, timeout=10.0))
- timed_out, structured_block_finished, outer_code_reached = (
- loop.run_until_complete(t2)
- )
- self.assertFalse(timed_out)
- self.assertTrue(structured_block_finished)
- self.assertTrue(outer_code_reached)
- self.assertEqual(t2.cancelling(), 0)
+ try:
+ # Test which timed out.
+ t1 = self.new_task(loop, make_request_with_timeout(sleep=10.0, timeout=0.1))
+ timed_out, structured_block_finished, outer_code_reached = (
+ loop.run_until_complete(t1)
+ )
+ self.assertTrue(timed_out)
+ self.assertFalse(structured_block_finished) # it was cancelled
+ self.assertTrue(outer_code_reached) # task got uncancelled after leaving
+ # the structured block and continued until
+ # completion
+ self.assertEqual(t1.cancelling(), 0) # no pending cancellation of the outer task
+
+ # Test which did not time out.
+ t2 = self.new_task(loop, make_request_with_timeout(sleep=0, timeout=10.0))
+ timed_out, structured_block_finished, outer_code_reached = (
+ loop.run_until_complete(t2)
+ )
+ self.assertFalse(timed_out)
+ self.assertTrue(structured_block_finished)
+ self.assertTrue(outer_code_reached)
+ self.assertEqual(t2.cancelling(), 0)
+ finally:
+ loop.close()
def test_cancel(self):
More information about the Python-checkins
mailing list