@@ -190,11 +190,11 @@ async def lockit():
190190 call_count += 1
191191 await lock .acquire ()
192192 lock_count += 1
193-
193+
194194 async def lockandtrigger ():
195195 await lock .acquire ()
196196 self .loop .call_soon (trigger )
197-
197+
198198 def trigger ():
199199 t1 .cancel ()
200200 lock .release ()
@@ -224,8 +224,6 @@ def trigger():
224224 test_utils .run_briefly (self .loop )
225225 self .assertTrue (t3 .cancelled ())
226226
227-
228-
229227 def test_finished_waiter_cancelled (self ):
230228 lock = asyncio .Lock (loop = self .loop )
231229
@@ -557,6 +555,31 @@ def test_wait_cancel_contested(self):
557555
558556 self .assertTrue (cond .locked ())
559557
558+ def test_wait_cancel_after_notify (self ):
559+ # See bpo-32841
560+ cond = asyncio .Condition (loop = self .loop )
561+ waited = False
562+
563+ async def wait_on_cond ():
564+ nonlocal waited
565+ async with cond :
566+ waited = True # Make sure this area was reached
567+ await cond .wait ()
568+
569+ waiter = asyncio .ensure_future (wait_on_cond (), loop = self .loop )
570+ test_utils .run_briefly (self .loop ) # Start waiting
571+
572+ self .loop .run_until_complete (cond .acquire ())
573+ cond .notify ()
574+ test_utils .run_briefly (self .loop ) # Get to acquire()
575+ waiter .cancel ()
576+ test_utils .run_briefly (self .loop ) # Activate cancellation
577+ cond .release ()
578+ test_utils .run_briefly (self .loop ) # Cancellation should occur
579+
580+ self .assertTrue (waiter .cancelled ())
581+ self .assertTrue (waited )
582+
560583 def test_wait_unacquired (self ):
561584 cond = asyncio .Condition (loop = self .loop )
562585 self .assertRaises (
0 commit comments