summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_tasks.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-11-05 19:29:04 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-11-05 19:29:04 (GMT)
commitade0412613f7628e34d947168cd5f447fa6b8f17 (patch)
treead5a538d7b910663c15a4e40cdca8f98a74108c8 /Lib/test/test_asyncio/test_tasks.py
parent5be2dac560018fee60c9435d19362117b9221677 (diff)
downloadcpython-ade0412613f7628e34d947168cd5f447fa6b8f17.zip
cpython-ade0412613f7628e34d947168cd5f447fa6b8f17.tar.gz
cpython-ade0412613f7628e34d947168cd5f447fa6b8f17.tar.bz2
asyncio: Optimize asyncio.sleep(0)
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 9772bae..b492cf0 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2188,5 +2188,29 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
self.assertEqual(context['exception'], exc_context.exception)
+class SleepTests(test_utils.TestCase):
+ def setUp(self):
+ self.loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(None)
+
+ def test_sleep_zero(self):
+ result = 0
+
+ def inc_result(num):
+ nonlocal result
+ result += num
+
+ @asyncio.coroutine
+ def coro():
+ self.loop.call_soon(inc_result, 1)
+ self.assertEqual(result, 0)
+ num = yield from asyncio.sleep(0, loop=self.loop, result=10)
+ self.assertEqual(result, 1) # inc'ed by call_soon
+ inc_result(num) # num should be 11
+
+ self.loop.run_until_complete(coro())
+ self.assertEqual(result, 11)
+
+
if __name__ == '__main__':
unittest.main()