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 | 2303fecedcfbdec16999e054e401dfad3a13fc05 (patch) | |
| tree | a52770710e7c945da52045702767c41edfa35a7f /Lib/test | |
| parent | b13177885f05f44f859e4bccfc0b551f1771a88b (diff) | |
| download | cpython-2303fecedcfbdec16999e054e401dfad3a13fc05.zip cpython-2303fecedcfbdec16999e054e401dfad3a13fc05.tar.gz cpython-2303fecedcfbdec16999e054e401dfad3a13fc05.tar.bz2 | |
asyncio: Change as_completed() to use a Queue, to avoid O(N**2) behavior. Fixes issue #20566.
Diffstat (limited to 'Lib/test')
| -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(): |
