|
16 | 16 | from redis.exceptions import LockError, LockNotOwnedError |
17 | 17 | from servicelib.redis import ( |
18 | 18 | CouldNotAcquireLockError, |
19 | | - LockLostError, |
20 | 19 | RedisClientSDK, |
21 | 20 | RedisClientsManager, |
22 | 21 | RedisManagerDBConfig, |
23 | 22 | ) |
24 | 23 | from servicelib.redis import _constants as redis_constants |
25 | | -from servicelib.redis._decorators import exclusive |
26 | 24 | from servicelib.utils import limited_gather |
27 | 25 | from settings_library.redis import RedisDatabase, RedisSettings |
28 | 26 | from tenacity import ( |
@@ -152,42 +150,6 @@ async def test_redis_lock_with_ttl( |
152 | 150 | assert not await ttl_lock.locked() |
153 | 151 |
|
154 | 152 |
|
155 | | -async def test_lock_context( |
156 | | - redis_client_sdk: RedisClientSDK, faker: Faker, lock_timeout: datetime.timedelta |
157 | | -): |
158 | | - lock_name = faker.pystr() |
159 | | - assert await _is_locked(redis_client_sdk, lock_name) is False |
160 | | - async with redis_client_sdk.lock_context(lock_name) as ttl_lock: |
161 | | - assert await _is_locked(redis_client_sdk, lock_name) is True |
162 | | - assert await ttl_lock.owned() is True |
163 | | - await asyncio.sleep(5 * lock_timeout.total_seconds()) |
164 | | - assert await _is_locked(redis_client_sdk, lock_name) is True |
165 | | - assert await ttl_lock.owned() is True |
166 | | - assert await _is_locked(redis_client_sdk, lock_name) is False |
167 | | - assert await ttl_lock.owned() is False |
168 | | - |
169 | | - |
170 | | -async def test_lock_context_raises_if_lock_is_lost( |
171 | | - redis_client_sdk: RedisClientSDK, faker: Faker |
172 | | -): |
173 | | - lock_name = faker.pystr() |
174 | | - started_event = asyncio.Event() |
175 | | - |
176 | | - @exclusive(redis_client_sdk, lock_key=lock_name) |
177 | | - async def _(time_to_sleep: datetime.timedelta) -> datetime.timedelta: |
178 | | - started_event.set() |
179 | | - await asyncio.sleep(time_to_sleep.total_seconds()) |
180 | | - return time_to_sleep |
181 | | - |
182 | | - exclusive_task = asyncio.create_task(_(datetime.timedelta(seconds=10))) |
183 | | - await asyncio.wait_for(started_event.wait(), timeout=2) |
184 | | - # let's simlulate lost lock by forcefully deleting it |
185 | | - await redis_client_sdk._client.delete(lock_name) # noqa: SLF001 |
186 | | - |
187 | | - with pytest.raises(LockLostError): |
188 | | - await exclusive_task |
189 | | - |
190 | | - |
191 | 153 | async def test_lock_context_with_already_locked_lock_raises( |
192 | 154 | redis_client_sdk: RedisClientSDK, faker: Faker |
193 | 155 | ): |
|
0 commit comments