()
| 408 | |
| 409 | |
| 410 | async def test_Condition() -> None: |
| 411 | with pytest.raises(TypeError): |
| 412 | Condition(Semaphore(1)) # type: ignore[arg-type] |
| 413 | with pytest.raises(TypeError): |
| 414 | Condition(StrictFIFOLock) # type: ignore[arg-type] |
| 415 | l = Lock() # noqa |
| 416 | c = Condition(l) |
| 417 | assert not l.locked() |
| 418 | assert not c.locked() |
| 419 | with assert_checkpoints(): |
| 420 | await c.acquire() |
| 421 | assert l.locked() |
| 422 | assert c.locked() |
| 423 | |
| 424 | c = Condition() |
| 425 | assert not c.locked() |
| 426 | c.acquire_nowait() |
| 427 | assert c.locked() |
| 428 | with pytest.raises(RuntimeError): |
| 429 | c.acquire_nowait() |
| 430 | c.release() |
| 431 | |
| 432 | with pytest.raises(RuntimeError): |
| 433 | # Can't wait without holding the lock |
| 434 | await c.wait() |
| 435 | with pytest.raises(RuntimeError): |
| 436 | # Can't notify without holding the lock |
| 437 | c.notify() |
| 438 | with pytest.raises(RuntimeError): |
| 439 | # Can't notify without holding the lock |
| 440 | c.notify_all() |
| 441 | |
| 442 | finished_waiters = set() |
| 443 | |
| 444 | async def waiter(i: int) -> None: |
| 445 | async with c: |
| 446 | await c.wait() |
| 447 | finished_waiters.add(i) |
| 448 | |
| 449 | async with _core.open_nursery() as nursery: |
| 450 | for i in range(3): |
| 451 | nursery.start_soon(waiter, i) |
| 452 | await wait_all_tasks_blocked() |
| 453 | async with c: |
| 454 | c.notify() |
| 455 | assert c.locked() |
| 456 | await wait_all_tasks_blocked() |
| 457 | assert finished_waiters == {0} |
| 458 | async with c: |
| 459 | c.notify_all() |
| 460 | await wait_all_tasks_blocked() |
| 461 | assert finished_waiters == {0, 1, 2} |
| 462 | |
| 463 | finished_waiters = set() |
| 464 | async with _core.open_nursery() as nursery: |
| 465 | for i in range(3): |
| 466 | nursery.start_soon(waiter, i) |
| 467 | await wait_all_tasks_blocked() |
nothing calls this directly
no test coverage detected
searching dependent graphs…