Пример #1
0
 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)
Пример #2
0
 def create_pool(self, max_size = 1, max_idle = 10, max_age = 10, connect_timeout= 0.5, module=None):
     if module is None:
         module = self._dbmodule
     return db_pool.RawConnectionPool(module,
         min_size=0, max_size=max_size, 
         max_idle=max_idle, max_age=max_age,
         connect_timeout=connect_timeout,
         **self._auth)
Пример #3
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

    with pool.item(cleanup=cleanup_mock):
        pass
    assert cleanup_mock.call_count == 2
Пример #4
0
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

    with pool.item() as conn:
        pass
    assert cleanup_mock.call_count == 2
Пример #5
0
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
Пример #6
0
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