def test_maxsize(self):

    def gen():
        when = (yield)
        self.assertAlmostEqual(0.01, when)
        when = (yield 0.01)
        self.assertAlmostEqual(0.02, when)
        (yield 0.01)
    loop = self.new_test_loop(gen)
    q = asyncio.Queue(maxsize=2, loop=loop)
    self.assertEqual(2, q.maxsize)
    have_been_put = []

    @asyncio.coroutine
    def putter():
        for i in range(3):
            (yield from q.put(i))
            have_been_put.append(i)
        return True

    @asyncio.coroutine
    def test():
        t = asyncio.Task(putter(), loop=loop)
        (yield from asyncio.sleep(0.01, loop=loop))
        self.assertEqual([0, 1], have_been_put)
        self.assertEqual(0, q.get_nowait())
        (yield from asyncio.sleep(0.01, loop=loop))
        self.assertEqual([0, 1, 2], have_been_put)
        self.assertEqual(1, q.get_nowait())
        self.assertEqual(2, q.get_nowait())
        self.assertTrue(t.done())
        self.assertTrue(t.result())
    loop.run_until_complete(test())
    self.assertAlmostEqual(0.02, loop.time())
def test_maxsize(self):

    def gen():
        when = (yield)
        self.assertAlmostEqual(0.01, when)
        when = (yield 0.01)
        self.assertAlmostEqual(0.02, when)
        (yield 0.01)
    loop = self.new_test_loop(gen)
    q = asyncio.Queue(maxsize=2, loop=loop)
    self.assertEqual(2, q.maxsize)
    have_been_put = []

    @asyncio.coroutine
    def putter():
        for i in range(3):
            (yield from q.put(i))
            have_been_put.append(i)
        return True

    @asyncio.coroutine
    def test():
        t = asyncio.Task(putter(), loop=loop)
        (yield from asyncio.sleep(0.01, loop=loop))
        self.assertEqual([0, 1], have_been_put)
        self.assertEqual(0, q.get_nowait())
        (yield from asyncio.sleep(0.01, loop=loop))
        self.assertEqual([0, 1, 2], have_been_put)
        self.assertEqual(1, q.get_nowait())
        self.assertEqual(2, q.get_nowait())
        self.assertTrue(t.done())
        self.assertTrue(t.result())
    loop.run_until_complete(test())
    self.assertAlmostEqual(0.02, loop.time())