diff --git a/eventlet/db_pool.py b/eventlet/db_pool.py index e68513f..d388c19 100644 --- a/eventlet/db_pool.py +++ b/eventlet/db_pool.py @@ -246,10 +246,9 @@ class TpooledConnectionPool(BaseConnectionPool): connections. """ def create(self): - return self.connect(self._db_module, - self.connect_timeout, - *self._args, - **self._kwargs) + now = time.time() + return now, now, self.connect(self._db_module, + self.connect_timeout, *self._args, **self._kwargs) @classmethod def connect(cls, db_module, connect_timeout, *args, **kw): @@ -266,10 +265,9 @@ class RawConnectionPool(BaseConnectionPool): """A pool which gives out plain database connections. """ def create(self): - return self.connect(self._db_module, - self.connect_timeout, - *self._args, - **self._kwargs) + now = time.time() + return now, now, self.connect(self._db_module, + self.connect_timeout, *self._args, **self._kwargs) @classmethod def connect(cls, db_module, connect_timeout, *args, **kw): @@ -353,7 +351,7 @@ class PooledConnectionWrapper(GenericConnectionWrapper): self._destroy() def __del__(self): - return # this causes some issues if __del__ is called in the + return # this causes some issues if __del__ is called in the # main coroutine, so for now this is disabled #self.close() diff --git a/tests/db_pool_test.py b/tests/db_pool_test.py index 2a316b0..7109883 100644 --- a/tests/db_pool_test.py +++ b/tests/db_pool_test.py @@ -45,6 +45,7 @@ class DBTester(object): if close_connection: connection.close() + # silly mock class class Mock(object): pass @@ -437,6 +438,15 @@ class DBConnectionPool(DBTester): self.assertEquals(self.pool.free(), 1) +class DummyConnection(object): + pass + + +class DummyDBModule(object): + def connect(self, *args, **kwargs): + return DummyConnection() + + class RaisingDBModule(object): def connect(self, *args, **kw): raise RuntimeError() @@ -478,8 +488,20 @@ class RawConnectionPool(DBConnectionPool): connect_timeout=connect_timeout, **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) + + get_auth = get_database_auth + def mysql_requirement(_f): verbose = os.environ.get('eventlet_test_mysql_verbose') try: @@ -498,6 +520,7 @@ def mysql_requirement(_f): print >> sys.stderr, ">> Skipping mysql tests, MySQLdb not importable" return False + class MysqlConnectionPool(object): dummy_table_sql = """CREATE TEMPORARY TABLE test_table ( @@ -545,9 +568,11 @@ class MysqlConnectionPool(object): class Test01MysqlTpool(MysqlConnectionPool, TpoolConnectionPool, TestCase): __test__ = True + class Test02MysqlRaw(MysqlConnectionPool, RawConnectionPool, TestCase): __test__ = True + def postgres_requirement(_f): try: import psycopg2 @@ -612,11 +637,14 @@ class Psycopg2ConnectionPool(object): db.close() del db + class Test01Psycopg2Tpool(Psycopg2ConnectionPool, TpoolConnectionPool, TestCase): __test__ = True + class Test02Psycopg2Raw(Psycopg2ConnectionPool, RawConnectionPool, TestCase): __test__ = True + if __name__ == '__main__': main()