# Path: rpaas/lock.py
# def lock(self, lock_name, timeout):
#     position = self._find_lock_pos(lock_name)
#     if position is not None:
#         return self.redis_locks[position].acquire(blocking=False)
#     self.redis_locks.append(self.redis_conn.lock(name=lock_name, timeout=timeout, blocking_timeout=1))
#     position = self._find_lock_pos(lock_name)
#     return self.redis_locks[position].acquire(blocking=False)


import redis
import unittest
import time
from rpaas import lock
        lock_acquire_2 = lock_manager.lock("lock2", 60)
        lock_acquire_3 = lock_manager.lock("lock3", 60)
        self.assertEqual(len(lock_manager.redis_locks), 3)
        self.assertTrue(lock_acquire_1)
        self.assertTrue(lock_acquire_2)
        self.assertTrue(lock_acquire_3)

    def test_unlock_and_release_lock(self):
        lock_manager = lock.Lock(self.redis_conn)
        lock_manager.lock("lock1", 60)
        lock1 = lock_manager.redis_locks[0]
        lock_manager.unlock("lock1")
        self.assertEqual(len(lock_manager.redis_locks), 0)
        with self.assertRaises(redis.exceptions.LockError) as cm:
            lock1.release()
        self.assertEqual(cm.exception.message, "Cannot release an unlocked lock")

    def test_unlock_and_release_lock_with_multiple_locks(self):
        lock_manager = lock.Lock(self.redis_conn)
        lock_acquire_1 = lock_manager.lock("lock1", 60)
        lock_acquire_2 = lock_manager.lock("lock2", 60)
        lock_acquire_3 = lock_manager.lock("lock3", 60)
        self.assertTrue(lock_acquire_1)
        self.assertTrue(lock_acquire_2)
        self.assertTrue(lock_acquire_3)
        lock2 = lock_manager.redis_locks[1]
        self.assertEqual(lock2.name, "lock2")
        lock_manager.unlock("lock2")
        self.assertEqual(len(lock_manager.redis_locks), 2)
        lock_acquire_1 = lock_manager.lock("lock1", 60)

# Path: rpaas/lock.py
# def lock(self, lock_name, timeout):
#     position = self._find_lock_pos(lock_name)
#     if position is not None:
#         return self.redis_locks[position].acquire(blocking=False)
#     self.redis_locks.append(self.redis_conn.lock(name=lock_name, timeout=timeout, blocking_timeout=1))
#     position = self._find_lock_pos(lock_name)
#     return self.redis_locks[position].acquire(blocking=False)


# Path: tests/test_lock.py
import redis
import unittest
import time
from rpaas import lock

        lock_acquire_2 = lock_manager.lock("lock2", 60)
        lock_acquire_3 = lock_manager.lock("lock3", 60)
        self.assertEqual(len(lock_manager.redis_locks), 3)
        self.assertTrue(lock_acquire_1)
        self.assertTrue(lock_acquire_2)
        self.assertTrue(lock_acquire_3)

    def test_unlock_and_release_lock(self):
        lock_manager = lock.Lock(self.redis_conn)
        lock_manager.lock("lock1", 60)
        lock1 = lock_manager.redis_locks[0]
        lock_manager.unlock("lock1")
        self.assertEqual(len(lock_manager.redis_locks), 0)
        with self.assertRaises(redis.exceptions.LockError) as cm:
            lock1.release()
        self.assertEqual(cm.exception.message, "Cannot release an unlocked lock")

    def test_unlock_and_release_lock_with_multiple_locks(self):
        lock_manager = lock.Lock(self.redis_conn)
        lock_acquire_1 = lock_manager.lock("lock1", 60)
        lock_acquire_2 = lock_manager.lock("lock2", 60)
        lock_acquire_3 = lock_manager.lock("lock3", 60)
        self.assertTrue(lock_acquire_1)
        self.assertTrue(lock_acquire_2)
        self.assertTrue(lock_acquire_3)
        lock2 = lock_manager.redis_locks[1]
        self.assertEqual(lock2.name, "lock2")
        lock_manager.unlock("lock2")
        self.assertEqual(len(lock_manager.redis_locks), 2)
        lock_acquire_1 = lock_manager.lock("lock1", 60)

        lock_acquire_2 = lock_manager.lock("lock2", 60)