コード例 #1
0
def test_new_connections_used(get_connection):
    pool = ConnectionPool(get_connection, initial_connections=0)

    o = pool.get_connection()
    o1 = pool.get_connection()

    assert o1 != o
コード例 #2
0
def test_new_connections_used(get_connection):
    pool = ConnectionPool(get_connection, initial_connections=0)

    o = pool.get_connection()
    o1 = pool.get_connection()

    assert o1 != o
コード例 #3
0
def test_connections_recycled(get_connection):
    pool = ConnectionPool(get_connection, initial_connections=0)

    o = pool.get_connection()
    pool.release_connection(o)
    o1 = pool.get_connection()
    o2 = pool.get_connection()

    assert o1 == o
    assert o1 != o2
コード例 #4
0
def test_connections_get_recycled(get_connection):
    pool = ConnectionPool(get_connection,
                          initial_connections=1,
                          max_connections=1,
                          recycle=3600)

    conn = pool.get_connection()
    pool.release_connection(conn)
    conn2 = pool.get_connection()
    pool.release_connection(conn2)

    assert conn == conn2

    with patch.object(conn2, 'is_stale', return_value=True):
        conn3 = pool.get_connection()

    assert conn3 != conn
    assert conn3 != conn2
コード例 #5
0
def test_max_connections_raises(get_connection):
    pool = ConnectionPool(
        get_connection, initial_connections=0, max_connections=2)

    pool.get_connection()
    pool.get_connection()

    with pytest.raises(ClientUnavailableError):
        pool.get_connection(next_timeout=0)
コード例 #6
0
def test_connections_recycled(get_connection):
    pool = ConnectionPool(get_connection, initial_connections=0)

    o = pool.get_connection()
    pool.release_connection(o)
    o1 = pool.get_connection()
    o2 = pool.get_connection()

    assert o1 == o
    assert o1 != o2
コード例 #7
0
def test_connections_get_recycled(get_connection):
    pool = ConnectionPool(
        get_connection,
        initial_connections=1,
        max_connections=1,
        recycle=3600
    )

    conn = pool.get_connection()
    pool.release_connection(conn)
    conn2 = pool.get_connection()
    pool.release_connection(conn2)

    assert conn == conn2

    with patch.object(conn2, 'is_stale', return_value=True):
        conn3 = pool.get_connection()

    assert conn3 != conn
    assert conn3 != conn2
コード例 #8
0
def test_creates_initial_connections(get_connection):
    pool = ConnectionPool(get_connection, initial_connections=2)
    assert get_connection.call_count == 2