summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorDiogo Dutra <diogodutradamata@gmail.com>2020-11-10 22:12:52 (GMT)
committerGitHub <noreply@github.com>2020-11-10 22:12:52 (GMT)
commit7e5ef0a5713f968f6e942566c78bf57ffbef01de (patch)
treee7dcc62f4df41be1087ef1f313a132dd401161e2 /Lib/test/test_asyncio
parenta13b26cac1519dad7bbc8651de7b826df7389d75 (diff)
downloadcpython-7e5ef0a5713f968f6e942566c78bf57ffbef01de.zip
cpython-7e5ef0a5713f968f6e942566c78bf57ffbef01de.tar.gz
cpython-7e5ef0a5713f968f6e942566c78bf57ffbef01de.tar.bz2
bpo-42140: Improve asyncio.wait function (GH-22938)
# Improve asyncio.wait function The original code creates the futures set two times. We can create this set before, avoiding the second creation. This new behaviour [breaks the aiokafka library](https://github.com/aio-libs/aiokafka/pull/672), because it gives an iterator to that function, so the second iteration become empty. Automerge-Triggered-By: GH:1st1
Diffstat (limited to 'Lib/test/test_asyncio')
-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 74fc1e4..01f62b7 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1548,6 +1548,30 @@ class BaseTaskTests:
loop.advance_time(10)
loop.run_until_complete(asyncio.wait([a, b]))
+ def test_wait_with_iterator_of_tasks(self):
+
+ def gen():
+ when = yield
+ self.assertAlmostEqual(0.1, when)
+ when = yield 0
+ self.assertAlmostEqual(0.15, when)
+ yield 0.15
+
+ loop = self.new_test_loop(gen)
+
+ a = self.new_task(loop, asyncio.sleep(0.1))
+ b = self.new_task(loop, asyncio.sleep(0.15))
+
+ async def foo():
+ done, pending = await asyncio.wait(iter([b, a]))
+ self.assertEqual(done, set([a, b]))
+ self.assertEqual(pending, set())
+ return 42
+
+ res = loop.run_until_complete(self.new_task(loop, foo()))
+ self.assertEqual(res, 42)
+ self.assertAlmostEqual(0.15, loop.time())
+
def test_as_completed(self):
def gen():