MCPcopy Index your code
hub / github.com/python/cpython / test_notify

Method test_notify

Lib/test/test_asyncio/test_locks.py:572–622  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

570 await cond.wait_for(lambda: False)
571
572 async def test_notify(self):
573 cond = asyncio.Condition()
574 result = []
575
576 async def c1(result):
577 await cond.acquire()
578 if await cond.wait():
579 result.append(1)
580 cond.release()
581 return True
582
583 async def c2(result):
584 await cond.acquire()
585 if await cond.wait():
586 result.append(2)
587 cond.release()
588 return True
589
590 async def c3(result):
591 await cond.acquire()
592 if await cond.wait():
593 result.append(3)
594 cond.release()
595 return True
596
597 t1 = asyncio.create_task(c1(result))
598 t2 = asyncio.create_task(c2(result))
599 t3 = asyncio.create_task(c3(result))
600
601 await asyncio.sleep(0)
602 self.assertEqual([], result)
603
604 await cond.acquire()
605 cond.notify(1)
606 cond.release()
607 await asyncio.sleep(0)
608 self.assertEqual([1], result)
609
610 await cond.acquire()
611 cond.notify(1)
612 cond.notify(2048)
613 cond.release()
614 await asyncio.sleep(0)
615 self.assertEqual([1, 2, 3], result)
616
617 self.assertTrue(t1.done())
618 self.assertTrue(t1.result())
619 self.assertTrue(t2.done())
620 self.assertTrue(t2.result())
621 self.assertTrue(t3.done())
622 self.assertTrue(t3.result())
623
624 async def test_notify_all(self):
625 cond = asyncio.Condition()

Callers

nothing calls this directly

Calls 10

notifyMethod · 0.95
assertTrueMethod · 0.80
ConditionMethod · 0.45
create_taskMethod · 0.45
sleepMethod · 0.45
assertEqualMethod · 0.45
acquireMethod · 0.45
releaseMethod · 0.45
doneMethod · 0.45
resultMethod · 0.45

Tested by

no test coverage detected