summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_base_events.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-20 15:34:15 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-20 15:34:15 (GMT)
commit0e6f52a2114d4fb3bf196e6a17e3b5daea3c0cdc (patch)
tree4ab5314c8ad9a589834cf0c8a1bc1a89b9327b75 /Lib/test/test_asyncio/test_base_events.py
parent4932e14542e10191b6b598307641f6b54c5da239 (diff)
downloadcpython-0e6f52a2114d4fb3bf196e6a17e3b5daea3c0cdc.zip
cpython-0e6f52a2114d4fb3bf196e6a17e3b5daea3c0cdc.tar.gz
cpython-0e6f52a2114d4fb3bf196e6a17e3b5daea3c0cdc.tar.bz2
asyncio, Tulip issue 105: in debug mode, log callbacks taking more than 100 ms
to be executed.
Diffstat (limited to 'Lib/test/test_asyncio/test_base_events.py')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 059b41c..352af48 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -969,6 +969,34 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
with self.assertRaises(TypeError):
self.loop.run_in_executor(None, coroutine_function)
+ @mock.patch('asyncio.base_events.logger')
+ def test_log_slow_callbacks(self, m_logger):
+ def stop_loop_cb(loop):
+ loop.stop()
+
+ @asyncio.coroutine
+ def stop_loop_coro(loop):
+ yield from ()
+ loop.stop()
+
+ asyncio.set_event_loop(self.loop)
+ self.loop.set_debug(True)
+ self.loop.slow_callback_duration = 0.0
+
+ # slow callback
+ self.loop.call_soon(stop_loop_cb, self.loop)
+ self.loop.run_forever()
+ fmt, *args = m_logger.warning.call_args[0]
+ self.assertRegex(fmt % tuple(args),
+ "^Executing Handle.*stop_loop_cb.* took .* seconds$")
+
+ # slow task
+ asyncio.async(stop_loop_coro(self.loop), loop=self.loop)
+ self.loop.run_forever()
+ fmt, *args = m_logger.warning.call_args[0]
+ self.assertRegex(fmt % tuple(args),
+ "^Executing Task.*stop_loop_coro.* took .* seconds$")
+
if __name__ == '__main__':
unittest.main()