summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Shepelev <temotor@gmail.com>2014-12-21 02:40:52 +0300
committerSergey Shepelev <temotor@gmail.com>2014-12-21 02:40:52 +0300
commit68b5641f22c02db67a622b09f4cbed5ed6be8b6e (patch)
treedac97293383c0265652c4b0aab79323334d7bc3b /tests
parent67b18bd3277d063912d37d5ed89f827ea209d12b (diff)
downloadeventlet-68b5641f22c02db67a622b09f4cbed5ed6be8b6e.tar.gz
tests: db_pool: test .clear() updates .current_size GH-139
Diffstat (limited to 'tests')
-rw-r--r--tests/db_pool_test.py100
1 files changed, 58 insertions, 42 deletions
diff --git a/tests/db_pool_test.py b/tests/db_pool_test.py
index 31179d1..9fc9ebc 100644
--- a/tests/db_pool_test.py
+++ b/tests/db_pool_test.py
@@ -453,7 +453,8 @@ class DBConnectionPool(DBTester):
class DummyConnection(object):
- pass
+ def rollback(self):
+ pass
class DummyDBModule(object):
@@ -505,54 +506,69 @@ class RawConnectionPool(DBConnectionPool):
**self._auth)
-class TestRawConnectionPool(TestCase):
- def test_issue_125(self):
- # pool = self.create_pool(min_size=3, max_size=5)
- pool = db_pool.RawConnectionPool(
- DummyDBModule(),
- dsn="dbname=test user=jessica port=5433",
- min_size=3, max_size=5)
- conn = pool.get()
- pool.put(conn)
+def test_raw_pool_issue_125():
+ # pool = self.create_pool(min_size=3, max_size=5)
+ pool = db_pool.RawConnectionPool(
+ DummyDBModule(),
+ dsn="dbname=test user=jessica port=5433",
+ min_size=3, max_size=5)
+ conn = pool.get()
+ pool.put(conn)
- def test_custom_cleanup_ok(self):
- cleanup_mock = mock.Mock()
- pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup_mock)
- conn = pool.get()
- pool.put(conn)
- assert cleanup_mock.call_count == 1
- with pool.item() as conn:
- pass
- assert cleanup_mock.call_count == 2
+def test_raw_pool_custom_cleanup_ok():
+ cleanup_mock = mock.Mock()
+ pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup_mock)
+ conn = pool.get()
+ pool.put(conn)
+ assert cleanup_mock.call_count == 1
- def test_custom_cleanup_arg_error(self):
- cleanup_mock = mock.Mock(side_effect=NotImplementedError)
- pool = db_pool.RawConnectionPool(DummyDBModule())
- conn = pool.get()
- pool.put(conn, cleanup=cleanup_mock)
- assert cleanup_mock.call_count == 1
+ with pool.item() as conn:
+ pass
+ assert cleanup_mock.call_count == 2
- with pool.item(cleanup=cleanup_mock):
- pass
- assert cleanup_mock.call_count == 2
- def test_custom_cleanup_fatal(self):
- state = [0]
+def test_raw_pool_custom_cleanup_arg_error():
+ cleanup_mock = mock.Mock(side_effect=NotImplementedError)
+ pool = db_pool.RawConnectionPool(DummyDBModule())
+ conn = pool.get()
+ pool.put(conn, cleanup=cleanup_mock)
+ assert cleanup_mock.call_count == 1
- def cleanup(conn):
- state[0] += 1
- raise KeyboardInterrupt
+ with pool.item(cleanup=cleanup_mock):
+ pass
+ assert cleanup_mock.call_count == 2
- pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup)
- conn = pool.get()
- try:
- pool.put(conn)
- except KeyboardInterrupt:
- pass
- else:
- assert False, 'Expected KeyboardInterrupt'
- assert state[0] == 1
+
+def test_raw_pool_custom_cleanup_fatal():
+ state = [0]
+
+ def cleanup(conn):
+ state[0] += 1
+ raise KeyboardInterrupt
+
+ pool = db_pool.RawConnectionPool(DummyDBModule(), cleanup=cleanup)
+ conn = pool.get()
+ try:
+ pool.put(conn)
+ except KeyboardInterrupt:
+ pass
+ else:
+ assert False, 'Expected KeyboardInterrupt'
+ 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