Skip to content

Commit 58de786

Browse files
committed
added tests with external registry
1 parent 8599207 commit 58de786

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

services/director/tests/unit/test_registry_proxy.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# pylint: disable=W0613, W0621
22
# pylint: disable=unused-variable
33

4+
import asyncio
45
import json
56
import time
67

78
import pytest
89
from fastapi import FastAPI
10+
from pytest_benchmark.plugin import BenchmarkFixture
911
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1012
from pytest_simcore.helpers.typing_env import EnvVarsDict
13+
from settings_library.docker_registry import RegistrySettings
1114
from simcore_service_director import registry_proxy
1215
from simcore_service_director.core.settings import ApplicationSettings
1316

@@ -203,6 +206,19 @@ async def test_get_image_details(
203206
assert details == service_description
204207

205208

209+
async def test_list_services(
210+
configure_registry_access: EnvVarsDict,
211+
configure_number_concurrency_calls: EnvVarsDict,
212+
app: FastAPI,
213+
push_services,
214+
):
215+
await push_services(
216+
number_of_computational_services=21, number_of_interactive_services=21
217+
)
218+
services = await registry_proxy.list_services(app, registry_proxy.ServiceType.ALL)
219+
assert len(services) == 42
220+
221+
206222
@pytest.fixture
207223
def configure_registry_caching(
208224
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
@@ -237,17 +253,41 @@ async def test_registry_caching(
237253
print("time to retrieve services with cache: ", time_to_retrieve_with_cache)
238254

239255

240-
@pytest.mark.skip(reason="test needs credentials to real registry")
241-
async def test_get_services_performance(
242-
configure_registry_access: EnvVarsDict,
256+
@pytest.fixture
257+
def configure_number_concurrency_calls(
258+
app_environment: EnvVarsDict,
259+
monkeypatch: pytest.MonkeyPatch,
260+
) -> EnvVarsDict:
261+
return app_environment | setenvs_from_dict(
262+
monkeypatch,
263+
envs={
264+
"DIRECTOR_REGISTRY_CLIENT_MAX_CONCURRENT_CALLS": "50",
265+
"DIRECTOR_REGISTRY_CLIENT_MAX_NUMBER_OF_RETRIEVED_OBJECTS": "50",
266+
},
267+
)
268+
269+
270+
def test_list_services_performance(
271+
configure_external_registry_access: EnvVarsDict,
272+
configure_number_concurrency_calls: EnvVarsDict,
273+
registry_settings: RegistrySettings,
243274
app: FastAPI,
275+
benchmark: BenchmarkFixture,
244276
):
245-
start_time = time.perf_counter()
246-
services = await registry_proxy.list_services(app, registry_proxy.ServiceType.ALL)
247-
stop_time = time.perf_counter()
248-
print(
249-
f"\nTime to run getting services: {stop_time - start_time}s, #services {len(services)}, time per call {(stop_time - start_time) / len(services)}s/service"
250-
)
277+
async def _list_services():
278+
start_time = time.perf_counter()
279+
services = await registry_proxy.list_services(
280+
app, registry_proxy.ServiceType.ALL
281+
)
282+
stop_time = time.perf_counter()
283+
print(
284+
f"\nTime to list services: {stop_time - start_time:.3}s, {len(services)} services in {registry_settings.resolved_registry_url}, rate: {(stop_time - start_time) / len(services or [1]):.3}s/service"
285+
)
286+
287+
def run_async_test() -> None:
288+
asyncio.get_event_loop().run_until_complete(_list_services())
289+
290+
benchmark.pedantic(run_async_test, rounds=1)
251291

252292

253293
async def test_generate_service_extras(

0 commit comments

Comments
 (0)