1414from faker import Faker
1515from pytest_mock import MockerFixture
1616from redis .exceptions import LockError , LockNotOwnedError
17- from servicelib import redis as servicelib_redis
1817from servicelib .redis import (
1918 CouldNotAcquireLockError ,
2019 LockLostError ,
2120 RedisClientSDK ,
2221 RedisClientsManager ,
2322 RedisManagerDBConfig ,
2423)
24+ from servicelib .redis import _constants as redis_constants
2525from servicelib .utils import limited_gather
2626from settings_library .redis import RedisDatabase , RedisSettings
2727from tenacity import (
@@ -63,7 +63,7 @@ def lock_timeout() -> datetime.timedelta:
6363@pytest .fixture
6464def mock_default_lock_ttl (mocker : MockerFixture ) -> None :
6565 mocker .patch .object (
66- servicelib_redis , "_DEFAULT_LOCK_TTL " , datetime .timedelta (seconds = 0.25 )
66+ redis_constants , "DEFAULT_LOCK_TTL " , datetime .timedelta (seconds = 0.25 )
6767 )
6868
6969
@@ -166,6 +166,7 @@ async def test_lock_context(
166166 assert await ttl_lock .owned () is False
167167
168168
169+ @pytest .mark .xfail (reason = "This test shows an issue, that will be fixed in the next PR" )
169170async def test_lock_context_raises_if_lock_is_lost (
170171 redis_client_sdk : RedisClientSDK , faker : Faker
171172):
@@ -180,7 +181,6 @@ async def test_lock_context_raises_if_lock_is_lost(
180181 await asyncio .sleep (20 )
181182
182183
183- @pytest .mark .xfail (reason = "This test shows an issue, that will be fixed in the next PR" )
184184async def test_lock_context_with_already_locked_lock_raises (
185185 redis_client_sdk : RedisClientSDK , faker : Faker
186186):
@@ -213,7 +213,7 @@ async def test_lock_context_with_data(redis_client_sdk: RedisClientSDK, faker: F
213213 lock_name = faker .pystr ()
214214 assert await _is_locked (redis_client_sdk , lock_name ) is False
215215 assert await redis_client_sdk .lock_value (lock_name ) is None
216- async with redis_client_sdk .lock_context (lock_name , lock_value = lock_data ) as lock :
216+ async with redis_client_sdk .lock_context (lock_name , lock_value = lock_data ):
217217 assert await _is_locked (redis_client_sdk , lock_name ) is True
218218 assert await redis_client_sdk .lock_value (lock_name ) == lock_data
219219 assert await _is_locked (redis_client_sdk , lock_name ) is False
@@ -254,18 +254,14 @@ async def race_condition_increase(self, by: int) -> None:
254254 current_value = self .value
255255 current_value += by
256256 # most likely situation which creates issues
257- await asyncio .sleep (
258- servicelib_redis ._DEFAULT_LOCK_TTL .total_seconds () / 2 # noqa: SLF001
259- )
257+ await asyncio .sleep (redis_constants .DEFAULT_LOCK_TTL .total_seconds () / 2 )
260258 self .value = current_value
261259
262260 counter = RaceConditionCounter ()
263261 lock_name : str = faker .pystr ()
264262 # ensures it does nto time out before acquiring the lock
265263 time_for_all_inc_counter_calls_to_finish_s : float = (
266- servicelib_redis ._DEFAULT_LOCK_TTL .total_seconds () # noqa: SLF001
267- * INCREASE_OPERATIONS
268- * 10
264+ redis_constants .DEFAULT_LOCK_TTL .total_seconds () * INCREASE_OPERATIONS * 10
269265 )
270266
271267 async def _inc_counter () -> None :
@@ -289,7 +285,7 @@ async def test_redis_client_sdks_manager(
289285 mock_redis_socket_timeout : None , redis_service : RedisSettings
290286):
291287 all_redis_configs : set [RedisManagerDBConfig ] = {
292- RedisManagerDBConfig (db ) for db in RedisDatabase
288+ RedisManagerDBConfig (database = db ) for db in RedisDatabase
293289 }
294290 manager = RedisClientsManager (
295291 databases_configs = all_redis_configs ,
@@ -335,7 +331,7 @@ async def test_redis_client_sdk_setup_shutdown(
335331@pytest .fixture
336332def mock_default_socket_timeout (mocker : MockerFixture ) -> None :
337333 mocker .patch .object (
338- servicelib_redis , "_DEFAULT_SOCKET_TIMEOUT " , datetime .timedelta (seconds = 0.25 )
334+ redis_constants , "DEFAULT_SOCKET_TIMEOUT " , datetime .timedelta (seconds = 0.25 )
339335 )
340336
341337
0 commit comments