tests: Fix ResourceWarnings related to unclosed transports · python/asyncio@1365ac3 (original) (raw)

`@@ -1157,21 +1157,28 @@ def getaddrinfo(*args, **kw):

`

1157

1157

`self.loop.add_writer = mock.Mock()

`

1158

1158

`self.loop.add_writer._is_coroutine = False

`

1159

1159

``

1160

``

`-

coro = self.loop.create_connection(MyProto, '1.2.3.4', 80)

`

1161

``

`-

self.loop.run_until_complete(coro)

`

1162

``

`-

sock.connect.assert_called_with(('1.2.3.4', 80))

`

1163

``

`-

m_socket.socket.assert_called_with(family=m_socket.AF_INET,

`

1164

``

`-

proto=m_socket.IPPROTO_TCP,

`

1165

``

`-

type=m_socket.SOCK_STREAM)

`

``

1160

`+

coro = self.loop.create_connection(asyncio.Protocol, '1.2.3.4', 80)

`

``

1161

`+

t, p = self.loop.run_until_complete(coro)

`

``

1162

`+

try:

`

``

1163

`+

sock.connect.assert_called_with(('1.2.3.4', 80))

`

``

1164

`+

m_socket.socket.assert_called_with(family=m_socket.AF_INET,

`

``

1165

`+

proto=m_socket.IPPROTO_TCP,

`

``

1166

`+

type=m_socket.SOCK_STREAM)

`

``

1167

`+

finally:

`

``

1168

`+

t.close()

`

``

1169

`+

test_utils.run_briefly(self.loop) # allow transport to close

`

1166

1170

``

1167

1171

`sock.family = socket.AF_INET6

`

1168

``

`-

coro = self.loop.create_connection(MyProto, '::2', 80)

`

1169

``

-

1170

``

`-

self.loop.run_until_complete(coro)

`

1171

``

`-

sock.connect.assert_called_with(('::2', 80))

`

1172

``

`-

m_socket.socket.assert_called_with(family=m_socket.AF_INET6,

`

1173

``

`-

proto=m_socket.IPPROTO_TCP,

`

1174

``

`-

type=m_socket.SOCK_STREAM)

`

``

1172

`+

coro = self.loop.create_connection(asyncio.Protocol, '::2', 80)

`

``

1173

`+

t, p = self.loop.run_until_complete(coro)

`

``

1174

`+

try:

`

``

1175

`+

sock.connect.assert_called_with(('::2', 80))

`

``

1176

`+

m_socket.socket.assert_called_with(family=m_socket.AF_INET6,

`

``

1177

`+

proto=m_socket.IPPROTO_TCP,

`

``

1178

`+

type=m_socket.SOCK_STREAM)

`

``

1179

`+

finally:

`

``

1180

`+

t.close()

`

``

1181

`+

test_utils.run_briefly(self.loop) # allow transport to close

`

1175

1182

``

1176

1183

`@patch_socket

`

1177

1184

`def test_create_connection_ip_addr(self, m_socket):

`

`@@ -1559,11 +1566,15 @@ def getaddrinfo(*args, **kw):

`

1559

1566

`reuse_address=False,

`

1560

1567

`reuse_port=reuseport_supported)

`

1561

1568

``

1562

``

`-

self.loop.run_until_complete(coro)

`

1563

``

`-

bind.assert_called_with(('1.2.3.4', 0))

`

1564

``

`-

m_socket.socket.assert_called_with(family=m_socket.AF_INET,

`

1565

``

`-

proto=m_socket.IPPROTO_UDP,

`

1566

``

`-

type=m_socket.SOCK_DGRAM)

`

``

1569

`+

t, p = self.loop.run_until_complete(coro)

`

``

1570

`+

try:

`

``

1571

`+

bind.assert_called_with(('1.2.3.4', 0))

`

``

1572

`+

m_socket.socket.assert_called_with(family=m_socket.AF_INET,

`

``

1573

`+

proto=m_socket.IPPROTO_UDP,

`

``

1574

`+

type=m_socket.SOCK_DGRAM)

`

``

1575

`+

finally:

`

``

1576

`+

t.close()

`

``

1577

`+

test_utils.run_briefly(self.loop) # allow transport to close

`

1567

1578

``

1568

1579

`def test_accept_connection_retry(self):

`

1569

1580

`sock = mock.Mock()

`