(self)
| 393 | class ConditionTests(unittest.IsolatedAsyncioTestCase): |
| 394 | |
| 395 | async def test_wait(self): |
| 396 | cond = asyncio.Condition() |
| 397 | result = [] |
| 398 | |
| 399 | async def c1(result): |
| 400 | await cond.acquire() |
| 401 | if await cond.wait(): |
| 402 | result.append(1) |
| 403 | return True |
| 404 | |
| 405 | async def c2(result): |
| 406 | await cond.acquire() |
| 407 | if await cond.wait(): |
| 408 | result.append(2) |
| 409 | return True |
| 410 | |
| 411 | async def c3(result): |
| 412 | await cond.acquire() |
| 413 | if await cond.wait(): |
| 414 | result.append(3) |
| 415 | return True |
| 416 | |
| 417 | t1 = asyncio.create_task(c1(result)) |
| 418 | t2 = asyncio.create_task(c2(result)) |
| 419 | t3 = asyncio.create_task(c3(result)) |
| 420 | |
| 421 | await asyncio.sleep(0) |
| 422 | self.assertEqual([], result) |
| 423 | self.assertFalse(cond.locked()) |
| 424 | |
| 425 | self.assertTrue(await cond.acquire()) |
| 426 | cond.notify() |
| 427 | await asyncio.sleep(0) |
| 428 | self.assertEqual([], result) |
| 429 | self.assertTrue(cond.locked()) |
| 430 | |
| 431 | cond.release() |
| 432 | await asyncio.sleep(0) |
| 433 | self.assertEqual([1], result) |
| 434 | self.assertTrue(cond.locked()) |
| 435 | |
| 436 | cond.notify(2) |
| 437 | await asyncio.sleep(0) |
| 438 | self.assertEqual([1], result) |
| 439 | self.assertTrue(cond.locked()) |
| 440 | |
| 441 | cond.release() |
| 442 | await asyncio.sleep(0) |
| 443 | self.assertEqual([1, 2], result) |
| 444 | self.assertTrue(cond.locked()) |
| 445 | |
| 446 | cond.release() |
| 447 | await asyncio.sleep(0) |
| 448 | self.assertEqual([1, 2, 3], result) |
| 449 | self.assertTrue(cond.locked()) |
| 450 | |
| 451 | self.assertTrue(t1.done()) |
| 452 | self.assertTrue(t1.result()) |
nothing calls this directly
no test coverage detected