66
77import pytest
88from fastapi import FastAPI
9+ from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
910from pytest_simcore .helpers .typing_env import EnvVarsDict
1011from simcore_service_director import registry_proxy
12+ from simcore_service_director .core .settings import ApplicationSettings
1113
1214
1315async 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+
204215async 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