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

Method test_wait_for

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

Source from the content-addressed store, hash-verified

523 await cond.wait()
524
525 async def test_wait_for(self):
526 cond = asyncio.Condition()
527 presult = False
528
529 def predicate():
530 return presult
531
532 result = []
533
534 async def c1(result):
535 await cond.acquire()
536 if await cond.wait_for(predicate):
537 result.append(1)
538 cond.release()
539 return True
540
541 t = asyncio.create_task(c1(result))
542
543 await asyncio.sleep(0)
544 self.assertEqual([], result)
545
546 await cond.acquire()
547 cond.notify()
548 cond.release()
549 await asyncio.sleep(0)
550 self.assertEqual([], result)
551
552 presult = True
553 await cond.acquire()
554 cond.notify()
555 cond.release()
556 await asyncio.sleep(0)
557 self.assertEqual([1], result)
558
559 self.assertTrue(t.done())
560 self.assertTrue(t.result())
561
562 async def test_wait_for_unacquired(self):
563 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