Exemplo n.º 1
0
def test_pool_is_full(mcache_params, loop):
    pool = MemcachePool(minsize=1, maxsize=2, loop=loop, **mcache_params)
    conn = yield from pool.acquire()

    # put garbage to the pool make it look like full
    mocked_conns = [_connection(0, 0), _connection(1, 1)]
    yield from pool._pool.put(mocked_conns[0])
    yield from pool._pool.put(mocked_conns[1])

    # try to return connection back
    assert pool.size() == 3
    pool.release(conn)
    assert pool.size() == 2
Exemplo n.º 2
0
    def test_pool_is_full(self):
        pool = MemcachePool('localhost', 11211,
                            minsize=1, maxsize=2, loop=self.loop)
        conn = yield from pool.acquire()

        # put garbage to the pool make it look like full
        mocked_conns = [_connection(0, 0), _connection(1, 1)]
        yield from pool._pool.put(mocked_conns[0])
        yield from pool._pool.put(mocked_conns[1])

        # try to return connection back
        self.assertEqual(pool.size(), 3)
        pool.release(conn)
        self.assertEqual(pool.size(), 2)
Exemplo n.º 3
0
def test_pool_acquire_release2(mcache_params, loop):
    pool = MemcachePool(minsize=1, maxsize=5, loop=loop, **mcache_params)
    reader, writer = yield from asyncio.open_connection(
        mcache_params['host'], mcache_params['port'], loop=loop)
    # put dead connection to the pool
    writer.close()
    reader.feed_eof()
    conn = _connection(reader, writer)
    yield from pool._pool.put(conn)
    conn = yield from pool.acquire()
    assert isinstance(conn.reader, asyncio.StreamReader)
    assert isinstance(conn.writer, asyncio.StreamWriter)
Exemplo n.º 4
0
def test_pool_acquire_release2(mcache_params, loop):
    pool = MemcachePool(minsize=1, maxsize=5, loop=loop, **mcache_params)
    reader, writer = yield from asyncio.open_connection(
        mcache_params['host'], mcache_params['port'], loop=loop)
    # put dead connection to the pool
    writer.close()
    reader.feed_eof()
    conn = _connection(reader, writer)
    yield from pool._pool.put(conn)
    conn = yield from pool.acquire()
    assert isinstance(conn.reader, asyncio.StreamReader)
    assert isinstance(conn.writer, asyncio.StreamWriter)
Exemplo n.º 5
0
 def test_pool_acquire_release2(self):
     pool = MemcachePool('localhost', 11211,
                         minsize=1, maxsize=5, loop=self.loop)
     reader, writer = yield from asyncio.open_connection(
         'localhost', 11211, loop=self.loop)
     # put dead connection to the pool
     writer.close()
     reader.feed_eof()
     conn = _connection(reader, writer)
     yield from pool._pool.put(conn)
     conn = yield from pool.acquire()
     self.assertIsInstance(conn.reader, asyncio.StreamReader)
     self.assertIsInstance(conn.writer, asyncio.StreamWriter)