summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_locks.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-06-09 21:08:23 (GMT)
committerGitHub <noreply@github.com>2017-06-09 21:08:23 (GMT)
commitd913d1c31733eff5969835e46ae13e2d156dbb1c (patch)
tree946c31193becaf4f136a9e8cb0c3e74e862388c2 /Lib/test/test_asyncio/test_locks.py
parent3fc2fa8cb909cb58325f56deb5cd500d278e4102 (diff)
downloadcpython-d913d1c31733eff5969835e46ae13e2d156dbb1c.zip
cpython-d913d1c31733eff5969835e46ae13e2d156dbb1c.tar.gz
cpython-d913d1c31733eff5969835e46ae13e2d156dbb1c.tar.bz2
Fix waiter cancellation in asyncio.Lock (#1031) (#2038)
Avoid a deadlock when the waiter who is about to take the lock is cancelled Issue #27585
Diffstat (limited to 'Lib/test/test_asyncio/test_locks.py')
-rw-r--r--Lib/test/test_asyncio/test_locks.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index 152948c..c85e8b1 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -176,6 +176,28 @@ class LockTests(test_utils.TestCase):
self.assertTrue(tb.cancelled())
self.assertTrue(tc.done())
+ def test_finished_waiter_cancelled(self):
+ lock = asyncio.Lock(loop=self.loop)
+
+ ta = asyncio.Task(lock.acquire(), loop=self.loop)
+ test_utils.run_briefly(self.loop)
+ self.assertTrue(lock.locked())
+
+ tb = asyncio.Task(lock.acquire(), loop=self.loop)
+ test_utils.run_briefly(self.loop)
+ self.assertEqual(len(lock._waiters), 1)
+
+ # Create a second waiter, wake up the first, and cancel it.
+ # Without the fix, the second was not woken up.
+ tc = asyncio.Task(lock.acquire(), loop=self.loop)
+ lock.release()
+ tb.cancel()
+ test_utils.run_briefly(self.loop)
+
+ self.assertTrue(lock.locked())
+ self.assertTrue(ta.done())
+ self.assertTrue(tb.cancelled())
+
def test_release_not_acquired(self):
lock = asyncio.Lock(loop=self.loop)