diff options
author | Guido van Rossum <guido@python.org> | 2014-02-13 01:58:19 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2014-02-13 01:58:19 (GMT) |
commit | b58f053e48923cba2708410bd215371a7d1d5250 (patch) | |
tree | bdb0dabc76f4d412fd3bb425b95c07ab5aeb38e5 /Lib/test/test_asyncio | |
parent | ee6dc425c895755c9fe27dee10e52e762b420c7b (diff) | |
download | cpython-b58f053e48923cba2708410bd215371a7d1d5250.zip cpython-b58f053e48923cba2708410bd215371a7d1d5250.tar.gz cpython-b58f053e48923cba2708410bd215371a7d1d5250.tar.bz2 |
asyncio: Change as_completed() to use a Queue, to avoid O(N**2) behavior. Fixes issue #20566.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 6847de0..024dd2e 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -779,7 +779,6 @@ class TaskTests(unittest.TestCase): yield 0 yield 0 yield 0.1 - yield 0.02 loop = test_utils.TestLoop(gen) self.addCleanup(loop.close) @@ -791,6 +790,8 @@ class TaskTests(unittest.TestCase): def foo(): values = [] for f in asyncio.as_completed([a, b], timeout=0.12, loop=loop): + if values: + loop.advance_time(0.02) try: v = yield from f values.append((1, v)) @@ -809,6 +810,26 @@ class TaskTests(unittest.TestCase): loop.advance_time(10) loop.run_until_complete(asyncio.wait([a, b], loop=loop)) + def test_as_completed_with_unused_timeout(self): + + def gen(): + yield + yield 0 + yield 0.01 + + loop = test_utils.TestLoop(gen) + self.addCleanup(loop.close) + + a = asyncio.sleep(0.01, 'a', loop=loop) + + @asyncio.coroutine + def foo(): + for f in asyncio.as_completed([a], timeout=1, loop=loop): + v = yield from f + self.assertEqual(v, 'a') + + res = loop.run_until_complete(asyncio.Task(foo(), loop=loop)) + def test_as_completed_reverse_wait(self): def gen(): |