@@ -104,106 +104,6 @@ async def test_redis_lock_with_ttl(
104104 assert not await ttl_lock .locked ()
105105
106106
107- # async def test_lock_context_with_already_locked_lock_raises(
108- # redis_client_sdk: RedisClientSDK, faker: Faker
109- # ):
110- # lock_name = faker.pystr()
111- # assert await _is_locked(redis_client_sdk, lock_name) is False
112- # async with redis_client_sdk.lock_context(lock_name) as lock:
113- # assert await _is_locked(redis_client_sdk, lock_name) is True
114-
115- # assert isinstance(lock.name, str)
116-
117- # # case where gives up immediately to acquire lock without waiting
118- # with pytest.raises(CouldNotAcquireLockError):
119- # async with redis_client_sdk.lock_context(lock.name, blocking=False):
120- # ...
121-
122- # # case when lock waits up to blocking_timeout_s before giving up on
123- # # lock acquisition
124- # with pytest.raises(CouldNotAcquireLockError):
125- # async with redis_client_sdk.lock_context(
126- # lock.name, blocking=True, blocking_timeout_s=0.1
127- # ):
128- # ...
129-
130- # assert await lock.locked() is True
131- # assert await _is_locked(redis_client_sdk, lock_name) is False
132-
133-
134- # async def test_lock_context_with_data(redis_client_sdk: RedisClientSDK, faker: Faker):
135- # lock_data = faker.text()
136- # lock_name = faker.pystr()
137- # assert await _is_locked(redis_client_sdk, lock_name) is False
138- # assert await redis_client_sdk.lock_value(lock_name) is None
139- # async with redis_client_sdk.lock_context(lock_name, lock_value=lock_data):
140- # assert await _is_locked(redis_client_sdk, lock_name) is True
141- # assert await redis_client_sdk.lock_value(lock_name) == lock_data
142- # assert await _is_locked(redis_client_sdk, lock_name) is False
143- # assert await redis_client_sdk.lock_value(lock_name) is None
144-
145-
146- # async def test_lock_context_released_after_error(
147- # redis_client_sdk: RedisClientSDK, faker: Faker
148- # ):
149- # lock_name = faker.pystr()
150-
151- # assert await redis_client_sdk.lock_value(lock_name) is None
152-
153- # with pytest.raises(RuntimeError):
154- # async with redis_client_sdk.lock_context(lock_name):
155- # assert await redis_client_sdk.redis.get(lock_name) is not None
156- # msg = "Expected error"
157- # raise RuntimeError(msg)
158-
159- # assert await redis_client_sdk.lock_value(lock_name) is None
160-
161-
162- # async def test_lock_acquired_in_parallel_to_update_same_resource(
163- # with_short_default_redis_lock_ttl: None,
164- # get_redis_client_sdk: Callable[
165- # [RedisDatabase], AbstractAsyncContextManager[RedisClientSDK]
166- # ],
167- # faker: Faker,
168- # ):
169- # INCREASE_OPERATIONS: Final[int] = 250
170- # INCREASE_BY: Final[int] = 10
171-
172- # class RaceConditionCounter:
173- # def __init__(self):
174- # self.value: int = 0
175-
176- # async def race_condition_increase(self, by: int) -> None:
177- # current_value = self.value
178- # current_value += by
179- # # most likely situation which creates issues
180- # await asyncio.sleep(redis_constants.DEFAULT_LOCK_TTL.total_seconds() / 2)
181- # self.value = current_value
182-
183- # counter = RaceConditionCounter()
184- # lock_name: str = faker.pystr()
185- # # ensures it does nto time out before acquiring the lock
186- # time_for_all_inc_counter_calls_to_finish_s: float = (
187- # redis_constants.DEFAULT_LOCK_TTL.total_seconds() * INCREASE_OPERATIONS * 10
188- # )
189-
190- # async def _inc_counter() -> None:
191- # async with get_redis_client_sdk(
192- # RedisDatabase.RESOURCES
193- # ) as redis_client_sdk:
194- # async with redis_client_sdk.lock_context(
195- # lock_key=lock_name,
196- # blocking=True,
197- # blocking_timeout_s=time_for_all_inc_counter_calls_to_finish_s,
198- # ):
199- # await counter.race_condition_increase(INCREASE_BY)
200-
201- # await limited_gather(
202- # *(_inc_counter() for _ in range(INCREASE_OPERATIONS)), limit=15
203- # )
204- # assert counter.value == INCREASE_BY * INCREASE_OPERATIONS
205-
206-
207107async def test_redis_client_sdk_setup_shutdown (
208108 mock_redis_socket_timeout : None , redis_service : RedisSettings
209109):
0 commit comments