Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_initialization(self):
instance = Instance(('localhost', 6379))
assert instance.connection == ('localhost', 6379)
assert instance._pool is None
assert isinstance(instance._lock, asyncio.Lock)
async def test_connect_pool_not_created(self, connection, address, redis_kwargs):
with patch('aioredlock.redis.Instance._create_redis_pool') as \
create_redis_pool:
fake_pool = FakePool()
create_redis_pool.side_effect = fake_create_redis_pool(fake_pool)
instance = Instance(connection)
assert instance._pool is None
pool = await instance.connect()
create_redis_pool.assert_called_once_with(
address, **redis_kwargs,
minsize=1, maxsize=100)
assert pool is fake_pool
assert instance._pool is fake_pool
def fake_instance(self):
with patch('aioredlock.redis.Instance._create_redis_pool') as \
create_redis_pool:
fake_pool = FakePool()
create_redis_pool.side_effect = fake_create_redis_pool(fake_pool)
instance = Instance(('localhost', 6379))
yield instance
async def test_connect_pool_already_created(self):
with patch('aioredlock.redis.Instance._create_redis_pool') as \
create_redis_pool:
instance = Instance(('localhost', 6379))
fake_pool = FakePool()
instance._pool = fake_pool
pool = await instance.connect()
assert not create_redis_pool.called
assert pool is fake_pool
async def test_connect_pool_aioredis_instance(self):
with patch('aioredlock.redis.Instance._create_redis_pool') as \
create_redis_pool:
redis_connection = await aioredis.create_redis_pool('redis://localhost')
instance = Instance(redis_connection)
await instance.connect()
assert not create_redis_pool.called
def __init__(self, redis_connections):
self.instances = []
for connection in redis_connections:
self.instances.append(Instance(connection))