Skip to content

Commit 9338e9a

Browse files
gh-98703: Add tests for closing _ProactorSocketTransport with proactor event loop (GH-98730)
(cherry picked from commit 96ae80f) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
1 parent bb80f6a commit 9338e9a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lib/test/test_asyncio/test_proactor_events.py

+21
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,27 @@ def test_force_close_idempotent(self):
296296
# and waiters will never be notified leading to hang.
297297
self.assertTrue(self.protocol.connection_lost.called)
298298

299+
def test_force_close_protocol_connection_lost_once(self):
300+
tr = self.socket_transport()
301+
self.assertFalse(self.protocol.connection_lost.called)
302+
tr._closing = True
303+
# Calling _force_close twice should not call
304+
# protocol.connection_lost twice
305+
tr._force_close(None)
306+
tr._force_close(None)
307+
test_utils.run_briefly(self.loop)
308+
self.assertEqual(1, self.protocol.connection_lost.call_count)
309+
310+
def test_close_protocol_connection_lost_once(self):
311+
tr = self.socket_transport()
312+
self.assertFalse(self.protocol.connection_lost.called)
313+
# Calling close twice should not call
314+
# protocol.connection_lost twice
315+
tr.close()
316+
tr.close()
317+
test_utils.run_briefly(self.loop)
318+
self.assertEqual(1, self.protocol.connection_lost.call_count)
319+
299320
def test_fatal_error_2(self):
300321
tr = self.socket_transport()
301322
tr._buffer = [b'data']

0 commit comments

Comments
 (0)