33# pylint: disable=too-many-arguments
44# pylint: disable=unused-argument
55# pylint: disable=unused-variable
6- import time
6+ import asyncio
77from collections .abc import Callable
88from random import randint
99from uuid import uuid4
2121 _ALIVE_SUFFIX ,
2222 _RESOURCE_SUFFIX ,
2323 RedisResourceRegistry ,
24+ UserSessionDict ,
2425 get_registry ,
2526)
2627from simcore_service_webserver .resource_manager .settings import get_plugin_settings
@@ -78,7 +79,7 @@ def redis_registry(redis_enabled_app: web.Application) -> RedisResourceRegistry:
7879
7980
8081@pytest .fixture
81- def create_user_ids ():
82+ def create_user_ids () -> Callable [..., list [ int ]] :
8283 def _do (number : int ) -> list [int ]:
8384 return list (range (number ))
8485
@@ -95,17 +96,22 @@ def _do(number: int) -> list[int]:
9596 ),
9697 ],
9798)
98- async def test_redis_registry_hashes (redis_enabled_app : web .Application , key , hash_key ):
99+ async def test_redis_registry_hashes (
100+ redis_enabled_app : web .Application , key : UserSessionDict , hash_key : str
101+ ):
99102 # pylint: disable=protected-access
100- assert RedisResourceRegistry ._hash_key (key ) == hash_key
103+ assert RedisResourceRegistry ._hash_key (key ) == hash_key # noqa: SLF001
101104 assert (
102- RedisResourceRegistry ._decode_hash_key (f"{ hash_key } :{ _RESOURCE_SUFFIX } " ) == key
105+ RedisResourceRegistry ._decode_hash_key (f"{ hash_key } :{ _RESOURCE_SUFFIX } " )
106+ == key # noqa: SLF001
103107 )
104- assert RedisResourceRegistry ._decode_hash_key (f"{ hash_key } :{ _ALIVE_SUFFIX } " ) == key
108+ assert (
109+ RedisResourceRegistry ._decode_hash_key (f"{ hash_key } :{ _ALIVE_SUFFIX } " ) == key
110+ ) # noqa: SLF001
105111
106112
107113async def test_redis_registry (redis_registry : RedisResourceRegistry ):
108- random_value = randint (1 , 10 )
114+ random_value = randint (1 , 10 ) # noqa: S311
109115 key = {f"key_{ x } " : f"value_{ x } " for x in range (random_value )}
110116 second_key = {f"sec_key_{ x } " : f"sec_value_{ x } " for x in range (random_value )}
111117 invalid_key = {"invalid_key" : "invalid_value" }
@@ -159,7 +165,7 @@ async def test_redis_registry(redis_registry: RedisResourceRegistry):
159165 assert all (x in alive_keys for x in [key , second_key ])
160166 assert all (x in [key , second_key ] for x in alive_keys )
161167
162- time .sleep (DEAD_KEY_TIMEOUT )
168+ await asyncio .sleep (DEAD_KEY_TIMEOUT )
163169
164170 assert await redis_registry .is_key_alive (second_key ) is False
165171 alive_keys , dead_keys = await redis_registry .get_all_resource_keys ()
@@ -181,7 +187,7 @@ async def test_redis_registry_key_will_always_expire(
181187 redis_registry : RedisResourceRegistry ,
182188):
183189 def get_random_int ():
184- return randint (1 , 10 )
190+ return randint (1 , 10 ) # noqa: S311
185191
186192 first_key = {f"key_{ x } " : f"value_{ x } " for x in range (get_random_int ())}
187193 second_key = {f"sec_key_{ x } " : f"sec_value_{ x } " for x in range (get_random_int ())}
@@ -199,7 +205,6 @@ def get_random_int():
199205 stop = stop_after_delay (5 ),
200206 reraise = True ,
201207 ):
202-
203208 with attempt :
204209 print (
205210 f"checking redis registry for keys alive, [attempt { attempt .retry_state .attempt_number } ]..."
@@ -240,7 +245,7 @@ async def test_users_sessions_resources_registry(
240245 "user_id" : f"{ user_id } " ,
241246 "client_session_id" : client_session_id ,
242247 }
243- assert rt ._resource_key () == user_session_key
248+ assert rt ._resource_key () == user_session_key # noqa: SLF001
244249
245250 # set the socket id and check it is rightfully there
246251 await rt .set_socket_id (socket_id )
@@ -263,10 +268,10 @@ async def test_users_sessions_resources_registry(
263268
264269 # resource key shall be filled
265270 assert await rt .find (res_key ) == [res_value ]
266- list_of_same_resource_users : list [
267- UserSessionID
268- ] = await rt . find_users_of_resource (
269- redis_enabled_app , res_key , res_value
271+ list_of_same_resource_users : list [UserSessionID ] = (
272+ await rt . find_users_of_resource (
273+ redis_enabled_app , res_key , res_value
274+ )
270275 )
271276 assert list_user_ids [: (list_user_ids .index (user_id ) + 1 )] == sorted (
272277 {
0 commit comments