]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-111644: Fix asyncio test_unhandled_exceptions() (GH-111713) (#111718)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 4 Nov 2023 06:29:20 +0000 (07:29 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Nov 2023 06:29:20 +0000 (06:29 +0000)
gh-111644: Fix asyncio test_unhandled_exceptions() (GH-111713)

Fix test_unhandled_exceptions() of test_asyncio.test_streams: break
explicitly a reference cycle.

Fix also StreamTests.tearDown(): the loop must not be closed
explicitly, but using set_event_loop() which takes care of shutting
down the executor with executor.shutdown(wait=True).
BaseEventLoop.close() calls executor.shutdown(wait=False).
(cherry picked from commit ac01e2243a1104b2154c0d1bdbc9f8d5b3ada778)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_asyncio/test_streams.py

index a0ed5ab798676829f9d4df59963fa6cd7dddd134..5a22232c00a36a0777de21142108470a66cf4016 100644 (file)
@@ -37,8 +37,7 @@ class StreamTests(test_utils.TestCase):
         # just in case if we have transport close callbacks
         test_utils.run_briefly(self.loop)
 
-        self.loop.close()
-        gc.collect()
+        # set_event_loop() takes care of closing self.loop in a safe way
         super().tearDown()
 
     def _basetest_open_connection(self, open_connection_fut):
@@ -1102,6 +1101,8 @@ os.close(fd)
 
         self.assertEqual(messages[0]['message'],
                          'Unhandled exception in client_connected_cb')
+        # Break explicitly reference cycle
+        messages = None
 
 
 if __name__ == '__main__':