summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-08-28 09:19:25 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-08-28 09:19:25 (GMT)
commit59e0802301e907873e392e0b25917fd0007a6252 (patch)
tree4dd13d5fedbe52b2e7327a46c91ebac0ec29e4e3 /Lib/test/test_asyncio
parentfeac3980ced0d80dc21982d87658876644c60e72 (diff)
downloadcpython-59e0802301e907873e392e0b25917fd0007a6252.zip
cpython-59e0802301e907873e392e0b25917fd0007a6252.tar.gz
cpython-59e0802301e907873e392e0b25917fd0007a6252.tar.bz2
asyncio, Tulip issue 201: Fix a race condition in wait_for()
Don't raise a TimeoutError if we reached the timeout and the future completed in the same iteration of the event loop. A side effect of the bug is that Queue.get() looses items.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 95cba54..e25aa4d 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -552,6 +552,21 @@ class TaskTests(test_utils.TestCase):
self.assertTrue(fut.done())
self.assertTrue(fut.cancelled())
+ def test_wait_for_race_condition(self):
+
+ def gen():
+ yield 0.1
+ yield 0.1
+ yield 0.1
+
+ loop = self.new_test_loop(gen)
+
+ fut = asyncio.Future(loop=loop)
+ task = asyncio.wait_for(fut, timeout=0.2, loop=loop)
+ loop.call_later(0.1, fut.set_result, "ok")
+ res = loop.run_until_complete(task)
+ self.assertEqual(res, "ok")
+
def test_wait(self):
def gen():