Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Aug 15, 2023
1 parent d7d1fa4 commit 0334b2c
Showing 1 changed file with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,58 @@
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import pytest
from faker import Faker
from fastapi import FastApi
from models_library.users import UserID
from models_library.wallets import WalletID
from servicelib.rabbitmq import RabbitMQClient
from simcore_service_clusters_keeper.clusters_api import create_cluster
from simcore_service_clusters_keeper.clusters_management_core import check_clusters
from types_aiobotocore_ec2 import EC2Client


@pytest.fixture
def user_id(faker: Faker) -> UserID:
return faker.pyint(min_value=1)


@pytest.fixture
def wallet_id(faker: Faker) -> WalletID:
return faker.pyint(min_value=1)


_FAST_TIME_BEFORE_TERMINATION_SECONDS: Final[int] = 10


@pytest.fixture
def app_environment(
app_environment: EnvVarsDict,
disabled_rabbitmq: None,
mocked_aws_server_envs: None,
mocked_redis_server: None,
monkeypatch: pytest.MonkeyPatch,
) -> EnvVarsDict:
# fast interval
monkeypatch.setenv(
"EC2_INSTANCES_TIME_BEFORE_TERMINATION",
f"{_FAST_TIME_BEFORE_TERMINATION_SECONDS}",
)
app_environment[
"EC2_INSTANCES_TIME_BEFORE_TERMINATION"
] = f"{_FAST_TIME_BEFORE_TERMINATION_SECONDS}"
return app_environment


@pytest.fixture
def _base_configuration(
aws_subnet_id: str,
aws_security_group_id: str,
aws_ami_id: str,
aws_allowed_ec2_instance_type_names: list[str],
) -> None:
...


async def test_cluster_management_core_properly_unused_instances(
disable_clusters_management_background_task: None,
Expand All @@ -10,7 +62,24 @@ async def test_cluster_management_core_properly_unused_instances(
ec2_client: EC2Client,
user_id: UserID,
wallet_id: WalletID,
initialized_app: FastApi,
):
await _create_cluster(
clusters_keeper_rabbitmq_rpc_client, ec2_client, user_id, wallet_id
created_clusters = await create_cluster(
initialized_app, user_id=user_id, wallet_id=wallet_id
)
assert len(created_clusters) == 1

# running the cluster management task shall not remove anything
await check_clusters(initialized_app)
_assert_cluster_exists()

# running the cluster management task after the heartbeat came in shall not remove anything
await asyncio.sleep(_FAST_TIME_BEFORE_TERMINATION_SECONDS + 1)
await cluster_heartbeat()
await check_clusters(initialized_app)
_assert_cluster_exists()

# after waiting the termination time, running the task shall remove the cluster
await asyncio.sleep(_FAST_TIME_BEFORE_TERMINATION_SECONDS + 1)
await check_clusters(initialized_app)
_assert_cluster_does_not_exists()

0 comments on commit 0334b2c

Please sign in to comment.