mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
asyncio: Close transports in tests
* Use test_utils.run_briefly() to execute pending calls to really close transports * sslproto: mock also _SSLPipe.shutdown(), it's need to close the transport * pipe test: the test doesn't close explicitly the PipeHandle, so ignore the warning instead * test_popen: use the context manager ("with p:") to explicitly close pipes
This commit is contained in:
parent
4bf22e033e
commit
ab8848bc2a
4 changed files with 15 additions and 3 deletions
|
@ -1180,6 +1180,8 @@ class SelectorSslTransportTests(test_utils.TestCase):
|
||||||
self.sslsock.do_handshake.side_effect = exc
|
self.sslsock.do_handshake.side_effect = exc
|
||||||
with test_utils.disable_logger():
|
with test_utils.disable_logger():
|
||||||
transport._on_handshake(0)
|
transport._on_handshake(0)
|
||||||
|
transport.close()
|
||||||
|
test_utils.run_briefly(self.loop)
|
||||||
|
|
||||||
def test_pause_resume_reading(self):
|
def test_pause_resume_reading(self):
|
||||||
tr = self._make_one()
|
tr = self._make_one()
|
||||||
|
|
|
@ -33,6 +33,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
|
||||||
waiter.cancel()
|
waiter.cancel()
|
||||||
transport = mock.Mock()
|
transport = mock.Mock()
|
||||||
sslpipe = mock.Mock()
|
sslpipe = mock.Mock()
|
||||||
|
sslpipe.shutdown.return_value = b''
|
||||||
sslpipe.do_handshake.side_effect = do_handshake
|
sslpipe.do_handshake.side_effect = do_handshake
|
||||||
with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
|
with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
|
||||||
ssl_proto.connection_made(transport)
|
ssl_proto.connection_made(transport)
|
||||||
|
@ -40,6 +41,9 @@ class SslProtoHandshakeTests(test_utils.TestCase):
|
||||||
with test_utils.disable_logger():
|
with test_utils.disable_logger():
|
||||||
self.loop.run_until_complete(handshake_fut)
|
self.loop.run_until_complete(handshake_fut)
|
||||||
|
|
||||||
|
# Close the transport
|
||||||
|
ssl_proto._app_transport.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -286,6 +286,7 @@ class SubprocessMixin:
|
||||||
# "Exception during subprocess creation, kill the subprocess"
|
# "Exception during subprocess creation, kill the subprocess"
|
||||||
with test_utils.disable_logger():
|
with test_utils.disable_logger():
|
||||||
self.loop.run_until_complete(cancel_make_transport())
|
self.loop.run_until_complete(cancel_make_transport())
|
||||||
|
test_utils.run_briefly(self.loop)
|
||||||
|
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import warnings
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
|
@ -115,8 +116,10 @@ class PipeTests(unittest.TestCase):
|
||||||
self.assertEqual(p.handle, h)
|
self.assertEqual(p.handle, h)
|
||||||
|
|
||||||
# check garbage collection of p closes handle
|
# check garbage collection of p closes handle
|
||||||
del p
|
with warnings.catch_warnings():
|
||||||
support.gc_collect()
|
warnings.filterwarnings("ignore", "", ResourceWarning)
|
||||||
|
del p
|
||||||
|
support.gc_collect()
|
||||||
try:
|
try:
|
||||||
_winapi.CloseHandle(h)
|
_winapi.CloseHandle(h)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -170,7 +173,9 @@ class PopenTests(unittest.TestCase):
|
||||||
self.assertTrue(msg.upper().rstrip().startswith(out))
|
self.assertTrue(msg.upper().rstrip().startswith(out))
|
||||||
self.assertTrue(b"stderr".startswith(err))
|
self.assertTrue(b"stderr".startswith(err))
|
||||||
|
|
||||||
p.wait()
|
# The context manager calls wait() and closes resources
|
||||||
|
with p:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue