summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_locks.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_locks.py')
-rw-r--r--Lib/test/test_asyncio/test_locks.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index 3e3dd79..8642aa8 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -214,11 +214,11 @@ class LockTests(test_utils.TestCase):
call_count += 1
await lock.acquire()
lock_count += 1
-
+
async def lockandtrigger():
await lock.acquire()
self.loop.call_soon(trigger)
-
+
def trigger():
t1.cancel()
lock.release()
@@ -248,8 +248,6 @@ class LockTests(test_utils.TestCase):
test_utils.run_briefly(self.loop)
self.assertTrue(t3.cancelled())
-
-
def test_finished_waiter_cancelled(self):
lock = asyncio.Lock(loop=self.loop)
@@ -576,6 +574,31 @@ class ConditionTests(test_utils.TestCase):
self.assertTrue(cond.locked())
+ def test_wait_cancel_after_notify(self):
+ # See bpo-32841
+ cond = asyncio.Condition(loop=self.loop)
+ waited = False
+
+ async def wait_on_cond():
+ nonlocal waited
+ async with cond:
+ waited = True # Make sure this area was reached
+ await cond.wait()
+
+ waiter = asyncio.ensure_future(wait_on_cond(), loop=self.loop)
+ test_utils.run_briefly(self.loop) # Start waiting
+
+ self.loop.run_until_complete(cond.acquire())
+ cond.notify()
+ test_utils.run_briefly(self.loop) # Get to acquire()
+ waiter.cancel()
+ test_utils.run_briefly(self.loop) # Activate cancellation
+ cond.release()
+ test_utils.run_briefly(self.loop) # Cancellation should occur
+
+ self.assertTrue(waiter.cancelled())
+ self.assertTrue(waited)
+
def test_wait_unacquired(self):
cond = asyncio.Condition(loop=self.loop)
self.assertRaises(