summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-06-11 16:00:07 (GMT)
committerYury Selivanov <yury@magic.io>2016-06-11 16:00:07 (GMT)
commitc92bf83a829956e683a3d6bb1ae65aed74d7b92a (patch)
treefee9f36c8042a41f709a3916baabfa95d91ad1cb /Lib/test
parentca2e0a48cf0dd663ba7457dc6bce60988cdfd56c (diff)
downloadcpython-c92bf83a829956e683a3d6bb1ae65aed74d7b92a.zip
cpython-c92bf83a829956e683a3d6bb1ae65aed74d7b92a.tar.gz
cpython-c92bf83a829956e683a3d6bb1ae65aed74d7b92a.tar.bz2
Issue #22970: asyncio: Fix inconsistency cancelling Condition.wait.
Patch by David Coles.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_locks.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index cdf5d9d..d3bdc51 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -457,6 +457,31 @@ class ConditionTests(test_utils.TestCase):
self.assertFalse(cond._waiters)
self.assertTrue(cond.locked())
+ def test_wait_cancel_contested(self):
+ cond = asyncio.Condition(loop=self.loop)
+
+ self.loop.run_until_complete(cond.acquire())
+ self.assertTrue(cond.locked())
+
+ wait_task = asyncio.Task(cond.wait(), loop=self.loop)
+ test_utils.run_briefly(self.loop)
+ self.assertFalse(cond.locked())
+
+ # Notify, but contest the lock before cancelling
+ self.loop.run_until_complete(cond.acquire())
+ self.assertTrue(cond.locked())
+ cond.notify()
+ self.loop.call_soon(wait_task.cancel)
+ self.loop.call_soon(cond.release)
+
+ try:
+ self.loop.run_until_complete(wait_task)
+ except asyncio.CancelledError:
+ # Should not happen, since no cancellation points
+ pass
+
+ self.assertTrue(cond.locked())
+
def test_wait_unacquired(self):
cond = asyncio.Condition(loop=self.loop)
self.assertRaises(