(self)
| 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() |
nothing calls this directly
no test coverage detected