Skip to content

Commit f77d887

Browse files
committed
add test
1 parent 4c0d9ea commit f77d887

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,24 @@ def task():
587587
self.assertFalse(t._must_cancel) # White-box test.
588588
self.assertFalse(t.cancel())
589589

590+
def test_cancel_at_end(self):
591+
"""coroutine end right after task is cancelled"""
592+
loop = asyncio.new_event_loop()
593+
self.set_event_loop(loop)
594+
595+
@asyncio.coroutine
596+
def task():
597+
t.cancel()
598+
self.assertTrue(t._must_cancel) # White-box test.
599+
return 12
600+
601+
t = self.new_task(loop, task())
602+
self.assertRaises(
603+
asyncio.CancelledError, loop.run_until_complete, t)
604+
self.assertTrue(t.done())
605+
self.assertFalse(t._must_cancel) # White-box test.
606+
self.assertFalse(t.cancel())
607+
590608
def test_stop_while_run_in_complete(self):
591609

592610
def gen():

0 commit comments

Comments
 (0)