summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-03-28 15:23:28 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2019-03-28 15:23:28 +0100
commite19b28f2bd89c047b12f6a8ffb1fe793834700d3 (patch)
tree8261b98b29eedb8ce67df4d571e8ba9b948d17ab /Lib/test/test_asyncio
parentf7868847da9f84cb68605b4b94d8fcc205e0766e (diff)
parent3eca28c61363a03b81b9fb12775490d6e42d8ecf (diff)
downloadcpython-git-e19b28f2bd89c047b12f6a8ffb1fe793834700d3.tar.gz
Merge branch 'master' into bind-socket
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py72
-rw-r--r--Lib/test/test_asyncio/test_tasks.py18
2 files changed, 81 insertions, 9 deletions
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index 19b7a4366b..7bc2ccf0bd 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -4,6 +4,7 @@ import logging
import socket
import sys
import unittest
+import weakref
from unittest import mock
try:
import ssl
@@ -274,6 +275,72 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
self.loop.run_until_complete(
asyncio.wait_for(client(srv.addr), timeout=10))
+ # No garbage is left if SSL is closed uncleanly
+ client_context = weakref.ref(client_context)
+ self.assertIsNone(client_context())
+
+ def test_create_connection_memory_leak(self):
+ HELLO_MSG = b'1' * self.PAYLOAD_SIZE
+
+ server_context = test_utils.simple_server_sslcontext()
+ client_context = test_utils.simple_client_sslcontext()
+
+ def serve(sock):
+ sock.settimeout(self.TIMEOUT)
+
+ sock.start_tls(server_context, server_side=True)
+
+ sock.sendall(b'O')
+ data = sock.recv_all(len(HELLO_MSG))
+ self.assertEqual(len(data), len(HELLO_MSG))
+
+ sock.shutdown(socket.SHUT_RDWR)
+ sock.close()
+
+ class ClientProto(asyncio.Protocol):
+ def __init__(self, on_data, on_eof):
+ self.on_data = on_data
+ self.on_eof = on_eof
+ self.con_made_cnt = 0
+
+ def connection_made(proto, tr):
+ # XXX: We assume user stores the transport in protocol
+ proto.tr = tr
+ proto.con_made_cnt += 1
+ # Ensure connection_made gets called only once.
+ self.assertEqual(proto.con_made_cnt, 1)
+
+ def data_received(self, data):
+ self.on_data.set_result(data)
+
+ def eof_received(self):
+ self.on_eof.set_result(True)
+
+ async def client(addr):
+ await asyncio.sleep(0.5)
+
+ on_data = self.loop.create_future()
+ on_eof = self.loop.create_future()
+
+ tr, proto = await self.loop.create_connection(
+ lambda: ClientProto(on_data, on_eof), *addr,
+ ssl=client_context)
+
+ self.assertEqual(await on_data, b'O')
+ tr.write(HELLO_MSG)
+ await on_eof
+
+ tr.close()
+
+ with self.tcp_server(serve, timeout=self.TIMEOUT) as srv:
+ self.loop.run_until_complete(
+ asyncio.wait_for(client(srv.addr), timeout=10))
+
+ # No garbage is left for SSL client from loop.create_connection, even
+ # if user stores the SSLTransport in corresponding protocol instance
+ client_context = weakref.ref(client_context)
+ self.assertIsNone(client_context())
+
def test_start_tls_client_buf_proto_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
@@ -562,6 +629,11 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
# exception or log an error, even if the handshake failed
self.assertEqual(messages, [])
+ # The 10s handshake timeout should be cancelled to free related
+ # objects without really waiting for 10s
+ client_sslctx = weakref.ref(client_sslctx)
+ self.assertIsNone(client_sslctx())
+
def test_create_connection_ssl_slow_handshake(self):
client_sslctx = test_utils.simple_client_sslcontext()
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 22f14f8762..1cdff528de 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1634,26 +1634,26 @@ class BaseTaskTests:
def test_current_task_deprecated(self):
Task = self.__class__.Task
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertIsNone(Task.current_task(loop=self.loop))
async def coro(loop):
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertIs(Task.current_task(loop=loop), task)
# See http://bugs.python.org/issue29271 for details:
asyncio.set_event_loop(loop)
try:
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertIs(Task.current_task(None), task)
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertIs(Task.current_task(), task)
finally:
asyncio.set_event_loop(None)
task = self.new_task(self.loop, coro(self.loop))
self.loop.run_until_complete(task)
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertIsNone(Task.current_task(loop=self.loop))
def test_current_task(self):
@@ -1982,7 +1982,7 @@ class BaseTaskTests:
Task = self.__class__.Task
async def coro():
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
assert Task.all_tasks(self.loop) == {t}
t = self.new_task(self.loop, coro())
@@ -2012,9 +2012,9 @@ class BaseTaskTests:
# See http://bugs.python.org/issue29271 for details:
asyncio.set_event_loop(self.loop)
try:
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertEqual(Task.all_tasks(), {task})
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertEqual(Task.all_tasks(None), {task})
finally:
asyncio.set_event_loop(None)
@@ -2692,7 +2692,7 @@ class BaseTaskIntrospectionTests:
self.assertEqual(asyncio.all_tasks(loop), set())
self._register_task(task)
self.assertEqual(asyncio.all_tasks(loop), set())
- with self.assertWarns(PendingDeprecationWarning):
+ with self.assertWarns(DeprecationWarning):
self.assertEqual(asyncio.Task.all_tasks(loop), {task})
self._unregister_task(task)