Skip to content

Commit 3c41761

Browse files
authored
[3.7] bpo-33789: Backport test_asyncio fixes from master (GH-7478)
* bpo-33789: test_asyncio: Fix ResourceWarning (GH-7460) * Close sockets and streams to fix ResourceWarning warnings * Catch also OSError to hide a traceback on an expected handshake error (cherry picked from commit 0eba7c3) * bpo-33789, test_asyncio: Hide PendingDeprecationWarning (GH-7461) Hide PendingDeprecationWarning in test__register_task_3(). (cherry picked from commit 7ed61e9) * bpo-32676, test_asyncio: Fix warning in test_error_in_call_soon() (GH-7462) Fix "<CoroWrapper ...> was never yielded from" warning in PyTask_PyFuture_Tests.test_error_in_call_soon() of test_asyncio.test_tasks. Close manually the coroutine on error. (cherry picked from commit 9f04f0d)
1 parent f38ace6 commit 3c41761

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Lib/test/test_asyncio/functional.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,14 @@ def start_tls(self, ssl_context, *,
150150
server_hostname=server_hostname,
151151
do_handshake_on_connect=False)
152152

153-
ssl_sock.do_handshake()
153+
try:
154+
ssl_sock.do_handshake()
155+
except:
156+
ssl_sock.close()
157+
raise
158+
finally:
159+
self.__sock.close()
154160

155-
self.__sock.close()
156161
self.__sock = ssl_sock
157162

158163
def __getattr__(self, name):

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ def server(sock):
600600
server_side=True)
601601
except ssl.SSLError:
602602
pass
603+
except OSError:
604+
pass
603605
finally:
604606
sock.close()
605607

@@ -636,6 +638,7 @@ def server(sock):
636638
except ssl.SSLError:
637639
pass
638640
finally:
641+
orig_sock.close()
639642
sock.close()
640643

641644
async def client(addr):
@@ -649,6 +652,8 @@ async def client(addr):
649652
writer.write(b'B')
650653
with self.assertRaises(ssl.SSLError):
651654
await reader.readline()
655+
656+
writer.close()
652657
return 'OK'
653658

654659
with self.tcp_server(server,

Lib/test/test_asyncio/test_tasks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,11 @@ def coro():
21782178
self.assertFalse(m_log.error.called)
21792179

21802180
with self.assertRaises(ValueError):
2181-
self.new_task(self.loop, coro())
2181+
gen = coro()
2182+
try:
2183+
self.new_task(self.loop, gen)
2184+
finally:
2185+
gen.close()
21822186

21832187
self.assertTrue(m_log.error.called)
21842188
message = m_log.error.call_args[0][0]
@@ -2609,7 +2613,8 @@ def done(self):
26092613
self.assertEqual(asyncio.all_tasks(loop), set())
26102614
self._register_task(task)
26112615
self.assertEqual(asyncio.all_tasks(loop), set())
2612-
self.assertEqual(asyncio.Task.all_tasks(loop), {task})
2616+
with self.assertWarns(PendingDeprecationWarning):
2617+
self.assertEqual(asyncio.Task.all_tasks(loop), {task})
26132618
self._unregister_task(task)
26142619

26152620
def test__enter_task(self):

0 commit comments

Comments
 (0)