summaryrefslogtreecommitdiff
path: root/tests/test_tasks.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-15 16:25:54 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-01-15 16:25:54 +0100
commitd0b9679f9198df2bfef2e9faaed70d68f9067271 (patch)
treeb3610ec747bf0c4615453b6675690535ced9fee8 /tests/test_tasks.py
parente70e384fcebeb63a4fc0e690e47b4d24437a5c95 (diff)
downloadtrollius-d0b9679f9198df2bfef2e9faaed70d68f9067271.tar.gz
Python issue #23219: cancelling wait_for() now cancels the task
Diffstat (limited to 'tests/test_tasks.py')
-rw-r--r--tests/test_tasks.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_tasks.py b/tests/test_tasks.py
index 7807dc0..06447d7 100644
--- a/tests/test_tasks.py
+++ b/tests/test_tasks.py
@@ -1705,6 +1705,33 @@ class TaskTests(test_utils.TestCase):
'test_task_source_traceback'))
self.loop.run_until_complete(task)
+ def _test_cancel_wait_for(self, timeout):
+ loop = asyncio.new_event_loop()
+ self.addCleanup(loop.close)
+
+ @asyncio.coroutine
+ def blocking_coroutine():
+ fut = asyncio.Future(loop=loop)
+ # Block: fut result is never set
+ yield from fut
+
+ task = loop.create_task(blocking_coroutine())
+
+ wait = loop.create_task(asyncio.wait_for(task, timeout, loop=loop))
+ loop.call_soon(wait.cancel)
+
+ self.assertRaises(asyncio.CancelledError,
+ loop.run_until_complete, wait)
+
+ # Python issue #23219: cancelling the wait must also cancel the task
+ self.assertTrue(task.cancelled())
+
+ def test_cancel_blocking_wait_for(self):
+ self._test_cancel_wait_for(None)
+
+ def test_cancel_wait_for(self):
+ self._test_cancel_wait_for(60.0)
+
class GatherTestsBase: