summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-08-26 18:26:28 (GMT)
committerGitHub <noreply@github.com>2020-08-26 18:26:28 (GMT)
commit6e1954cd8286e083e7f8d09516d91b6b15769a4e (patch)
tree45986fbbbe8f561525ca4bb8728afca7ab9af224 /Lib/test/test_asyncio
parent08045391a7aa87d4fbd3e8ef4c852c2fa4e81a8a (diff)
downloadcpython-6e1954cd8286e083e7f8d09516d91b6b15769a4e.zip
cpython-6e1954cd8286e083e7f8d09516d91b6b15769a4e.tar.gz
cpython-6e1954cd8286e083e7f8d09516d91b6b15769a4e.tar.bz2
bpo-37658: Fix asyncio.wait_for() to respect waited task status (GH-21894) (#21965)
Currently, if `asyncio.wait_for()` itself is cancelled it will always raise `CancelledError` regardless if the underlying task is still running. This is similar to a race with the timeout, which is handled already. (cherry picked from commit a2118a14627256197bddcf4fcecad4c264c1e39d) Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index c21b0693..a70dc0a 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -861,6 +861,22 @@ class BaseTaskTests:
res = loop.run_until_complete(task)
self.assertEqual(res, "ok")
+ def test_wait_for_cancellation_race_condition(self):
+ def gen():
+ yield 0.1
+ yield 0.1
+ yield 0.1
+ yield 0.1
+
+ loop = self.new_test_loop(gen)
+
+ fut = self.new_future(loop)
+ loop.call_later(0.1, fut.set_result, "ok")
+ task = loop.create_task(asyncio.wait_for(fut, timeout=1))
+ loop.call_later(0.1, task.cancel)
+ res = loop.run_until_complete(task)
+ self.assertEqual(res, "ok")
+
def test_wait_for_waits_for_task_cancellation(self):
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)