mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
asyncio/tests: Fix ResourceWarnings related to unclosed transports
This commit is contained in:
parent
5f68ca66bf
commit
3cd863c86e
1 changed files with 29 additions and 18 deletions
|
@ -1157,21 +1157,28 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
|
||||||
self.loop.add_writer = mock.Mock()
|
self.loop.add_writer = mock.Mock()
|
||||||
self.loop.add_writer._is_coroutine = False
|
self.loop.add_writer._is_coroutine = False
|
||||||
|
|
||||||
coro = self.loop.create_connection(MyProto, '1.2.3.4', 80)
|
coro = self.loop.create_connection(asyncio.Protocol, '1.2.3.4', 80)
|
||||||
self.loop.run_until_complete(coro)
|
t, p = self.loop.run_until_complete(coro)
|
||||||
sock.connect.assert_called_with(('1.2.3.4', 80))
|
try:
|
||||||
m_socket.socket.assert_called_with(family=m_socket.AF_INET,
|
sock.connect.assert_called_with(('1.2.3.4', 80))
|
||||||
proto=m_socket.IPPROTO_TCP,
|
m_socket.socket.assert_called_with(family=m_socket.AF_INET,
|
||||||
type=m_socket.SOCK_STREAM)
|
proto=m_socket.IPPROTO_TCP,
|
||||||
|
type=m_socket.SOCK_STREAM)
|
||||||
|
finally:
|
||||||
|
t.close()
|
||||||
|
test_utils.run_briefly(self.loop) # allow transport to close
|
||||||
|
|
||||||
sock.family = socket.AF_INET6
|
sock.family = socket.AF_INET6
|
||||||
coro = self.loop.create_connection(MyProto, '::2', 80)
|
coro = self.loop.create_connection(asyncio.Protocol, '::2', 80)
|
||||||
|
t, p = self.loop.run_until_complete(coro)
|
||||||
self.loop.run_until_complete(coro)
|
try:
|
||||||
sock.connect.assert_called_with(('::2', 80))
|
sock.connect.assert_called_with(('::2', 80))
|
||||||
m_socket.socket.assert_called_with(family=m_socket.AF_INET6,
|
m_socket.socket.assert_called_with(family=m_socket.AF_INET6,
|
||||||
proto=m_socket.IPPROTO_TCP,
|
proto=m_socket.IPPROTO_TCP,
|
||||||
type=m_socket.SOCK_STREAM)
|
type=m_socket.SOCK_STREAM)
|
||||||
|
finally:
|
||||||
|
t.close()
|
||||||
|
test_utils.run_briefly(self.loop) # allow transport to close
|
||||||
|
|
||||||
@patch_socket
|
@patch_socket
|
||||||
def test_create_connection_ip_addr(self, m_socket):
|
def test_create_connection_ip_addr(self, m_socket):
|
||||||
|
@ -1559,11 +1566,15 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
|
||||||
reuse_address=False,
|
reuse_address=False,
|
||||||
reuse_port=reuseport_supported)
|
reuse_port=reuseport_supported)
|
||||||
|
|
||||||
self.loop.run_until_complete(coro)
|
t, p = self.loop.run_until_complete(coro)
|
||||||
bind.assert_called_with(('1.2.3.4', 0))
|
try:
|
||||||
m_socket.socket.assert_called_with(family=m_socket.AF_INET,
|
bind.assert_called_with(('1.2.3.4', 0))
|
||||||
proto=m_socket.IPPROTO_UDP,
|
m_socket.socket.assert_called_with(family=m_socket.AF_INET,
|
||||||
type=m_socket.SOCK_DGRAM)
|
proto=m_socket.IPPROTO_UDP,
|
||||||
|
type=m_socket.SOCK_DGRAM)
|
||||||
|
finally:
|
||||||
|
t.close()
|
||||||
|
test_utils.run_briefly(self.loop) # allow transport to close
|
||||||
|
|
||||||
def test_accept_connection_retry(self):
|
def test_accept_connection_retry(self):
|
||||||
sock = mock.Mock()
|
sock = mock.Mock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue