Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
grant-aterlo committed Aug 16, 2016
1 parent 8cd6731 commit da0afc9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 2 additions & 4 deletions aiomcache/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ def release(self, conn):
if conn.reader.at_eof() or conn.reader.exception():
self._do_close(conn)
else:
try:
self._pool.put_nowait(conn)
except asyncio.QueueFull:
self._do_close(conn)
# This should never fail because poolsize=maxsize
self._pool.put_nowait(conn)

@asyncio.coroutine
def _create_new_conn(self):
Expand Down
31 changes: 31 additions & 0 deletions tests/pool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,34 @@ def acquire_wait_release():
yield from asyncio.gather(*([acquire_wait_release()] * 3), loop=loop)
assert pool.size() == 1
assert len(pool._in_use) == 0


@pytest.mark.run_loop
def test_maxsize_greater_than_minsize(mcache_params, loop):
pool = MemcachePool(minsize=5, maxsize=1, loop=loop, **mcache_params)
conn = yield from pool.acquire()
assert isinstance(conn.reader, asyncio.StreamReader)
assert isinstance(conn.writer, asyncio.StreamWriter)
pool.release(conn)


@pytest.mark.run_loop
def test_0_minsize(mcache_params, loop):
pool = MemcachePool(minsize=0, maxsize=5, loop=loop, **mcache_params)
conn = yield from pool.acquire()
assert isinstance(conn.reader, asyncio.StreamReader)
assert isinstance(conn.writer, asyncio.StreamWriter)
pool.release(conn)


@pytest.mark.run_loop
def test_bad_connection(mcache_params, loop):
pool = MemcachePool(minsize=5, maxsize=1, loop=loop, **mcache_params)
pool._host = "INVALID_HOST"
assert pool.size() == 0
with pytest.raises(BlockingIOError):
conn = yield from pool.acquire()
assert isinstance(conn.reader, asyncio.StreamReader)
assert isinstance(conn.writer, asyncio.StreamWriter)
pool.release(conn)
assert pool.size() == 0

0 comments on commit da0afc9

Please sign in to comment.