(self)
| 463 | self.assertRaises(ValueError, q.task_done) |
| 464 | |
| 465 | async def test_task_done(self): |
| 466 | q = self.q_class() |
| 467 | for i in range(100): |
| 468 | q.put_nowait(i) |
| 469 | |
| 470 | accumulator = 0 |
| 471 | |
| 472 | # Two workers get items from the queue and call task_done after each. |
| 473 | # Join the queue and assert all items have been processed. |
| 474 | running = True |
| 475 | |
| 476 | async def worker(): |
| 477 | nonlocal accumulator |
| 478 | |
| 479 | while running: |
| 480 | item = await q.get() |
| 481 | accumulator += item |
| 482 | q.task_done() |
| 483 | |
| 484 | async with asyncio.TaskGroup() as tg: |
| 485 | tasks = [tg.create_task(worker()) |
| 486 | for index in range(2)] |
| 487 | |
| 488 | await q.join() |
| 489 | self.assertEqual(sum(range(100)), accumulator) |
| 490 | |
| 491 | # close running generators |
| 492 | running = False |
| 493 | for i in range(len(tasks)): |
| 494 | q.put_nowait(0) |
| 495 | |
| 496 | async def test_join_empty_queue(self): |
| 497 | q = self.q_class() |
nothing calls this directly
no test coverage detected