(self)
| 29 | # - https://github.com/python/cpython/issues/112202 |
| 30 | class TestConditionStdlib(unittest.IsolatedAsyncioTestCase): |
| 31 | async def test_wait(self): |
| 32 | cond = _async_create_condition(_async_create_lock()) |
| 33 | result = [] |
| 34 | |
| 35 | async def c1(result): |
| 36 | await cond.acquire() |
| 37 | if await cond.wait(): |
| 38 | result.append(1) |
| 39 | return True |
| 40 | |
| 41 | async def c2(result): |
| 42 | await cond.acquire() |
| 43 | if await cond.wait(): |
| 44 | result.append(2) |
| 45 | return True |
| 46 | |
| 47 | async def c3(result): |
| 48 | await cond.acquire() |
| 49 | if await cond.wait(): |
| 50 | result.append(3) |
| 51 | return True |
| 52 | |
| 53 | t1 = asyncio.create_task(c1(result)) |
| 54 | t2 = asyncio.create_task(c2(result)) |
| 55 | t3 = asyncio.create_task(c3(result)) |
| 56 | |
| 57 | await asyncio.sleep(0) |
| 58 | self.assertEqual([], result) |
| 59 | self.assertFalse(cond.locked()) |
| 60 | |
| 61 | self.assertTrue(await cond.acquire()) |
| 62 | cond.notify() |
| 63 | await asyncio.sleep(0) |
| 64 | self.assertEqual([], result) |
| 65 | self.assertTrue(cond.locked()) |
| 66 | |
| 67 | cond.release() |
| 68 | await asyncio.sleep(0) |
| 69 | self.assertEqual([1], result) |
| 70 | self.assertTrue(cond.locked()) |
| 71 | |
| 72 | cond.notify(2) |
| 73 | await asyncio.sleep(0) |
| 74 | self.assertEqual([1], result) |
| 75 | self.assertTrue(cond.locked()) |
| 76 | |
| 77 | cond.release() |
| 78 | await asyncio.sleep(0) |
| 79 | self.assertEqual([1, 2], result) |
| 80 | self.assertTrue(cond.locked()) |
| 81 | |
| 82 | cond.release() |
| 83 | await asyncio.sleep(0) |
| 84 | self.assertEqual([1, 2, 3], result) |
| 85 | self.assertTrue(cond.locked()) |
| 86 | |
| 87 | self.assertTrue(t1.done()) |
| 88 | self.assertTrue(t1.result()) |
nothing calls this directly
no test coverage detected