tests: db_pool: test .clear() updates .current_size GH-139
This commit is contained in:
@@ -453,6 +453,7 @@ class DBConnectionPool(DBTester):
|
|||||||
|
|
||||||
|
|
||||||
class DummyConnection(object):
|
class DummyConnection(object):
|
||||||
|
def rollback(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -505,8 +506,7 @@ class RawConnectionPool(DBConnectionPool):
|
|||||||
**self._auth)
|
**self._auth)
|
||||||
|
|
||||||
|
|
||||||
class TestRawConnectionPool(TestCase):
|
def test_raw_pool_issue_125():
|
||||||
def test_issue_125(self):
|
|
||||||
# pool = self.create_pool(min_size=3, max_size=5)
|
# pool = self.create_pool(min_size=3, max_size=5)
|
||||||
pool = db_pool.RawConnectionPool(
|
pool = db_pool.RawConnectionPool(
|
||||||
DummyDBModule(),
|
DummyDBModule(),
|
||||||
@@ -515,7 +515,8 @@ class TestRawConnectionPool(TestCase):
|
|||||||
conn = pool.get()
|
conn = pool.get()
|
||||||
pool.put(conn)
|
pool.put(conn)
|
||||||
|
|
||||||
def test_custom_cleanup_ok(self):
|
|
||||||
|
def test_raw_pool_custom_cleanup_ok():
|
||||||
cleanup_mock = mock.Mock()
|
cleanup_mock = mock.Mock()
|
||||||
pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup_mock)
|
pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup_mock)
|
||||||
conn = pool.get()
|
conn = pool.get()
|
||||||
@@ -526,7 +527,8 @@ class TestRawConnectionPool(TestCase):
|
|||||||
pass
|
pass
|
||||||
assert cleanup_mock.call_count == 2
|
assert cleanup_mock.call_count == 2
|
||||||
|
|
||||||
def test_custom_cleanup_arg_error(self):
|
|
||||||
|
def test_raw_pool_custom_cleanup_arg_error():
|
||||||
cleanup_mock = mock.Mock(side_effect=NotImplementedError)
|
cleanup_mock = mock.Mock(side_effect=NotImplementedError)
|
||||||
pool = db_pool.RawConnectionPool(DummyDBModule())
|
pool = db_pool.RawConnectionPool(DummyDBModule())
|
||||||
conn = pool.get()
|
conn = pool.get()
|
||||||
@@ -537,7 +539,8 @@ class TestRawConnectionPool(TestCase):
|
|||||||
pass
|
pass
|
||||||
assert cleanup_mock.call_count == 2
|
assert cleanup_mock.call_count == 2
|
||||||
|
|
||||||
def test_custom_cleanup_fatal(self):
|
|
||||||
|
def test_raw_pool_custom_cleanup_fatal():
|
||||||
state = [0]
|
state = [0]
|
||||||
|
|
||||||
def cleanup(conn):
|
def cleanup(conn):
|
||||||
@@ -555,6 +558,19 @@ class TestRawConnectionPool(TestCase):
|
|||||||
assert state[0] == 1
|
assert state[0] == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_raw_pool_clear_update_current_size():
|
||||||
|
# https://github.com/eventlet/eventlet/issues/139
|
||||||
|
# BaseConnectionPool.clear does not update .current_size.
|
||||||
|
# That leads to situation when new connections could not be created.
|
||||||
|
pool = db_pool.RawConnectionPool(DummyDBModule())
|
||||||
|
pool.get().close()
|
||||||
|
assert pool.current_size == 1
|
||||||
|
assert len(pool.free_items) == 1
|
||||||
|
pool.clear()
|
||||||
|
assert pool.current_size == 0
|
||||||
|
assert len(pool.free_items) == 0
|
||||||
|
|
||||||
|
|
||||||
get_auth = get_database_auth
|
get_auth = get_database_auth
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user