|
1 | 1 | # pylint: disable=W0613, W0621 |
2 | 2 | # pylint: disable=unused-variable |
3 | 3 |
|
| 4 | +import asyncio |
4 | 5 | import json |
5 | 6 | import time |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 | from fastapi import FastAPI |
| 10 | +from pytest_benchmark.plugin import BenchmarkFixture |
9 | 11 | from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
10 | 12 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
| 13 | +from settings_library.docker_registry import RegistrySettings |
11 | 14 | from simcore_service_director import registry_proxy |
12 | 15 | from simcore_service_director.core.settings import ApplicationSettings |
13 | 16 |
|
@@ -203,6 +206,19 @@ async def test_get_image_details( |
203 | 206 | assert details == service_description |
204 | 207 |
|
205 | 208 |
|
| 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 | + |
206 | 222 | @pytest.fixture |
207 | 223 | def configure_registry_caching( |
208 | 224 | app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch |
@@ -237,17 +253,41 @@ async def test_registry_caching( |
237 | 253 | print("time to retrieve services with cache: ", time_to_retrieve_with_cache) |
238 | 254 |
|
239 | 255 |
|
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, |
243 | 274 | app: FastAPI, |
| 275 | + benchmark: BenchmarkFixture, |
244 | 276 | ): |
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) |
251 | 291 |
|
252 | 292 |
|
253 | 293 | async def test_generate_service_extras( |
|
0 commit comments