Skip to content

Commit 444c4c9

Browse files
committed
fixed test using monkeypatch
1 parent 0457aaa commit 444c4c9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

services/director/src/simcore_service_director/registry_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async def registry_request(
208208
cache: SimpleMemoryCache = app.state.registry_cache_memory
209209
cache_key = f"{method}_{path}"
210210
if not no_cache and (cached_response := await cache.get(cache_key)):
211-
assert isinstance(tuple[dict, Mapping], cached_response) # nosec
211+
assert isinstance(cached_response, tuple) # nosec
212212
return cast(tuple[dict, Mapping], cached_response)
213213

214214
app_settings = get_application_settings(app)

services/director/tests/unit/test_registry_proxy.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
import pytest
88
from fastapi import FastAPI
9+
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
910
from pytest_simcore.helpers.typing_env import EnvVarsDict
1011
from simcore_service_director import registry_proxy
12+
from simcore_service_director.core.settings import ApplicationSettings
1113

1214

1315
async def test_list_no_services_available(
@@ -201,16 +203,27 @@ async def test_get_image_details(
201203
assert details == service_description
202204

203205

206+
@pytest.fixture
207+
def configure_registry_caching(
208+
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
209+
) -> EnvVarsDict:
210+
return app_environment | setenvs_from_dict(
211+
monkeypatch, {"DIRECTOR_REGISTRY_CACHING": True}
212+
)
213+
214+
204215
async def test_registry_caching(
205216
configure_registry_access: EnvVarsDict,
217+
configure_registry_caching: EnvVarsDict,
218+
app_settings: ApplicationSettings,
206219
app: FastAPI,
207220
push_services,
208221
):
209222
images = await push_services(
210-
number_of_computational_services=1, number_of_interactive_services=1
223+
number_of_computational_services=21, number_of_interactive_services=21
211224
)
212-
# TODO: use monkeypatching
213-
# config.DIRECTOR_REGISTRY_CACHING = True
225+
assert app_settings.DIRECTOR_REGISTRY_CACHING is True
226+
214227
start_time = time.perf_counter()
215228
services = await registry_proxy.list_services(app, registry_proxy.ServiceType.ALL)
216229
time_to_retrieve_without_cache = time.perf_counter() - start_time
@@ -220,6 +233,8 @@ async def test_registry_caching(
220233
time_to_retrieve_with_cache = time.perf_counter() - start_time
221234
assert len(services) == len(images)
222235
assert time_to_retrieve_with_cache < time_to_retrieve_without_cache
236+
print("time to retrieve services without cache: ", time_to_retrieve_without_cache)
237+
print("time to retrieve services with cache: ", time_to_retrieve_with_cache)
223238

224239

225240
@pytest.mark.skip(reason="test needs credentials to real registry")

0 commit comments

Comments
 (0)