Example #1
0
def test_use_connection_cleanup_stack(redis, loop):
    """Ensure connection stack cleanup."""

    kwargs = dict(address=('localhost', 6379), loop=loop)
    yield from use_connection(**kwargs)
    assert len(_connection_stack) == 1
    push_connection(redis)      # Make test finalizer happy.
Example #2
0
def test_use_connection(redis, loop):
    """Replace connection stack."""

    kwargs = dict(address=('localhost', 6379), loop=loop)
    yield from use_connection(**kwargs)
    assert get_current_connection() != redis
    push_connection(redis)      # Make test finalizer happy.
Example #3
0
def test_use_connection_explicit_redis(redis, loop):
    """Pass redis connection explicitly."""

    connection = yield from find_connection(loop)
    yield from use_connection(redis=connection)
    assert get_current_connection() == connection
    push_connection(redis)      # Make test finalizer happy.
Example #4
0
 def coroutine(loop, kwargs):
     redis = yield from find_connection(loop)
     push_connection(redis)
     if 'redis' in kwargs:
         kwargs['redis'] = redis
     if 'loop' in kwargs:
         kwargs['loop'] = loop
     try:
         yield from asyncio.coroutine(f)(**kwargs)
     except Exception:
         raise
     else:
         connection = pop_connection()
         assert connection == redis, (
             'Wow, something really nasty happened to the '
             'Redis connection stack. Check your setup.')
     finally:
         yield from redis.flushdb()
         release_local(_connection_stack)