Skip to content

Commit 0d91088

Browse files
committed
refactor: enhance fixture definitions and environment setup for garbage collector tests
1 parent fc87e78 commit 0d91088

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

services/web/server/tests/unit/with_dbs/04/garbage_collector/conftest.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
from simcore_service_webserver.users.plugin import setup_users
3434

3535

36+
@pytest.fixture(scope="session")
37+
def service_name() -> str:
38+
# Overrides service_name fixture needed in docker_compose_service_environment_dict fixture
39+
return "wb-garbage-collector"
40+
41+
3642
@pytest.fixture(scope="session")
3743
def fast_service_deletion_delay() -> int:
3844
"""
@@ -46,20 +52,20 @@ def fast_service_deletion_delay() -> int:
4652
def app_environment(
4753
fast_service_deletion_delay: int,
4854
monkeypatch: pytest.MonkeyPatch,
49-
app_environment: EnvVarsDict,
55+
docker_compose_service_environment_dict: EnvVarsDict,
56+
env_devel_dict: EnvVarsDict,
5057
) -> EnvVarsDict:
51-
# NOTE: undos some app_environment settings
52-
monkeypatch.delenv("WEBSERVER_GARBAGE_COLLECTOR", raising=False)
53-
app_environment.pop("WEBSERVER_GARBAGE_COLLECTOR", None)
5458

55-
return app_environment | setenvs_from_dict(
59+
return setenvs_from_dict(
5660
monkeypatch,
5761
{
62+
**docker_compose_service_environment_dict,
5863
"WEBSERVER_COMPUTATION": "1",
5964
"WEBSERVER_NOTIFICATIONS": "1",
6065
# sets TTL of a resource after logout
6166
"RESOURCE_MANAGER_RESOURCE_TTL_S": f"{fast_service_deletion_delay}",
62-
"GARBAGE_COLLECTOR_INTERVAL_S": "30",
67+
# "WEBSERVER_PROJECTS must be enabled for close_project fixture"
68+
"WEBSERVER_PROJECTS": env_devel_dict["WEBSERVER_PROJECTS"],
6369
},
6470
)
6571

@@ -75,11 +81,8 @@ async def client(
7581
) -> TestClient:
7682
app = create_safe_application()
7783

78-
assert "WEBSERVER_GARBAGE_COLLECTOR" not in app_environment
79-
8084
settings = setup_settings(app)
8185
assert settings.WEBSERVER_GARBAGE_COLLECTOR is not None
82-
assert settings.WEBSERVER_PROJECTS is not None
8386

8487
setup_db(app)
8588
setup_session(app)
@@ -88,7 +91,12 @@ async def client(
8891
setup_login(app)
8992
setup_users(app)
9093
setup_socketio(app)
94+
95+
assert (
96+
settings.WEBSERVER_PROJECTS is not None
97+
), "WEBSERVER_PROJECTS must be enabled for close_project fixture"
9198
assert setup_projects(app)
99+
92100
setup_director_v2(app)
93101
assert setup_resource_manager(app)
94102
setup_rabbitmq(app)

services/web/server/tests/unit/with_dbs/04/garbage_collector/test_resource_manager_user_sessions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from aiohttp import web
1414
from faker import Faker
1515
from models_library.users import UserID
16+
from pytest_mock import MockerFixture
1617
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
18+
from pytest_simcore.helpers.typing_env import EnvVarsDict
1719
from servicelib.aiohttp.application import create_safe_application
1820
from servicelib.aiohttp.application_setup import is_setup_completed
1921
from simcore_service_webserver.application_settings import setup_settings
@@ -36,12 +38,11 @@
3638

3739

3840
@pytest.fixture
39-
def mock_env_devel_environment(
40-
mock_env_devel_environment: dict[str, str],
41+
def app_environment(
42+
app_environment: EnvVarsDict,
4143
monkeypatch: pytest.MonkeyPatch,
42-
faker: Faker,
43-
):
44-
return mock_env_devel_environment | setenvs_from_dict(
44+
) -> EnvVarsDict:
45+
return app_environment | setenvs_from_dict(
4546
monkeypatch,
4647
{
4748
"RESOURCE_MANAGER_RESOURCE_TTL_S": "3",
@@ -51,7 +52,7 @@ def mock_env_devel_environment(
5152

5253
@pytest.fixture
5354
def redis_enabled_app(
54-
redis_client: aioredis.Redis, mocker, mock_env_devel_environment
55+
redis_client: aioredis.Redis, mocker: MockerFixture, app_environment: EnvVarsDict
5556
) -> web.Application:
5657
# app.cleanup_ctx.append(redis_client) in setup_redis would create a client and connect
5758
# to a real redis service. Instead, we mock the get_redis_resources_client access

0 commit comments

Comments
 (0)