def test_task_done(self):
    q = self.q_class(loop=self.loop)
    for i in range(100):
        q.put_nowait(i)
    accumulator = 0
    running = True

    @asyncio.coroutine
    def worker():
        nonlocal accumulator
        while running:
            item = (yield from q.get())
            accumulator += item
            q.task_done()

    @asyncio.coroutine
    def test():
        tasks = [asyncio.Task(worker(), loop=self.loop) for index in range(2)]
        (yield from q.join())
        return tasks
    tasks = self.loop.run_until_complete(test())
    self.assertEqual(sum(range(100)), accumulator)
    running = False
    for i in range(len(tasks)):
        q.put_nowait(0)
    self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop))
def test_task_done(self):
    q = self.q_class(loop=self.loop)
    for i in range(100):
        q.put_nowait(i)
    accumulator = 0
    running = True

    @asyncio.coroutine
    def worker():
        nonlocal accumulator
        while running:
            item = (yield from q.get())
            accumulator += item
            q.task_done()

    @asyncio.coroutine
    def test():
        tasks = [asyncio.Task(worker(), loop=self.loop) for index in range(2)]
        (yield from q.join())
        return tasks
    tasks = self.loop.run_until_complete(test())
    self.assertEqual(sum(range(100)), accumulator)
    running = False
    for i in range(len(tasks)):
        q.put_nowait(0)
    self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop))