[Python-checkins] gh-98703: Add tests for closing `_ProactorSocketTransport` with proactor event loop (GH-98730)

miss-islington webhook-mailer at python.org
Wed Oct 26 23:35:12 EDT 2022


https://github.com/python/cpython/commit/9338e9a5f4418e4ddb2509d7c7b2e0a784abb614
commit: 9338e9a5f4418e4ddb2509d7c7b2e0a784abb614
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-10-26T20:35:07-07:00
summary:

gh-98703: Add tests for closing `_ProactorSocketTransport` with proactor event loop (GH-98730)

(cherry picked from commit 96ae80f1d004f2df4a707919853f0745c9c352d1)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>

files:
M Lib/test/test_asyncio/test_proactor_events.py

diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index 3b219609eefc..60b30c6a46a6 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -296,6 +296,27 @@ def test_force_close_idempotent(self):
         # and waiters will never be notified leading to hang.
         self.assertTrue(self.protocol.connection_lost.called)
 
+    def test_force_close_protocol_connection_lost_once(self):
+        tr = self.socket_transport()
+        self.assertFalse(self.protocol.connection_lost.called)
+        tr._closing = True
+        # Calling _force_close twice should not call
+        # protocol.connection_lost twice
+        tr._force_close(None)
+        tr._force_close(None)
+        test_utils.run_briefly(self.loop)
+        self.assertEqual(1, self.protocol.connection_lost.call_count)
+
+    def test_close_protocol_connection_lost_once(self):
+        tr = self.socket_transport()
+        self.assertFalse(self.protocol.connection_lost.called)
+        # Calling close twice should not call
+        # protocol.connection_lost twice
+        tr.close()
+        tr.close()
+        test_utils.run_briefly(self.loop)
+        self.assertEqual(1, self.protocol.connection_lost.call_count)
+
     def test_fatal_error_2(self):
         tr = self.socket_transport()
         tr._buffer = [b'data']



More information about the Python-checkins mailing list