summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-06-11 13:49:18 (GMT)
committerGitHub <noreply@github.com>2017-06-11 13:49:18 (GMT)
commit7ce1c6fb579a01bb184224a10019039fde9c8eaf (patch)
treecfae34038438eb189d445bcd6391c9c19607baf7 /Lib/test/test_asyncio
parent36ff451ebae41f09560bff582c95946474d898f8 (diff)
downloadcpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.zip
cpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.tar.gz
cpython-7ce1c6fb579a01bb184224a10019039fde9c8eaf.tar.bz2
bpo-30508: Don't log exceptions if Task/Future "cancel()" method called (#2050)
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_futures.py8
-rw-r--r--Lib/test/test_asyncio/test_tasks.py19
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 99336f8..5d4b2d2 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -319,6 +319,14 @@ class BaseFutureTests:
self.assertFalse(m_log.error.called)
@mock.patch('asyncio.base_events.logger')
+ def test_tb_logger_not_called_after_cancel(self, m_log):
+ fut = self._new_future(loop=self.loop)
+ fut.set_exception(Exception())
+ fut.cancel()
+ del fut
+ self.assertFalse(m_log.error.called)
+
+ @mock.patch('asyncio.base_events.logger')
def test_tb_logger_result_unretrieved(self, m_log):
fut = self._new_future(loop=self.loop)
fut.set_result(42)
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 988b288..686387f 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1864,6 +1864,25 @@ class BaseTaskTests:
})
mock_handler.reset_mock()
+ @mock.patch('asyncio.base_events.logger')
+ def test_tb_logger_not_called_after_cancel(self, m_log):
+ loop = asyncio.new_event_loop()
+ self.set_event_loop(loop)
+
+ @asyncio.coroutine
+ def coro():
+ raise TypeError
+
+ @asyncio.coroutine
+ def runner():
+ task = self.new_task(loop, coro())
+ yield from asyncio.sleep(0.05, loop=loop)
+ task.cancel()
+ task = None
+
+ loop.run_until_complete(runner())
+ self.assertFalse(m_log.error.called)
+
@mock.patch('asyncio.coroutines.logger')
def test_coroutine_never_yielded(self, m_log):
with set_coroutine_debug(True):