Skip to content

Commit 78db78f

Browse files
committed
renaming fixture
1 parent faeb390 commit 78db78f

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

services/autoscaling/tests/unit/conftest.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
Service,
5151
TaskSpec,
5252
)
53-
from pydantic import ByteSize, PositiveInt, TypeAdapter
53+
from pydantic import ByteSize, NonNegativeInt, PositiveInt, TypeAdapter
5454
from pytest_mock import MockType
5555
from pytest_mock.plugin import MockerFixture
5656
from pytest_simcore.helpers.host import get_localhost_ip
@@ -1005,10 +1005,22 @@ def _creator(
10051005

10061006

10071007
@pytest.fixture
1008-
def mock_machines_buffer(monkeypatch: pytest.MonkeyPatch) -> int:
1009-
num_machines_in_buffer = 5
1010-
monkeypatch.setenv("EC2_INSTANCES_MACHINES_BUFFER", f"{num_machines_in_buffer}")
1011-
return num_machines_in_buffer
1008+
def num_hot_buffer() -> NonNegativeInt:
1009+
return 5
1010+
1011+
1012+
@pytest.fixture
1013+
def with_instances_machines_hot_buffer(
1014+
num_hot_buffer: int,
1015+
app_environment: EnvVarsDict,
1016+
monkeypatch: pytest.MonkeyPatch,
1017+
) -> EnvVarsDict:
1018+
return app_environment | setenvs_from_dict(
1019+
monkeypatch,
1020+
{
1021+
"EC2_INSTANCES_MACHINES_BUFFER": f"{num_hot_buffer}",
1022+
},
1023+
)
10121024

10131025

10141026
@pytest.fixture

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async def test_cluster_scaling_with_no_services_does_nothing(
308308
async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expected_machines(
309309
patch_ec2_client_launch_instances_min_number_of_instances: mock.Mock,
310310
minimal_configuration: None,
311-
mock_machines_buffer: int,
311+
with_instances_machines_hot_buffer: EnvVarsDict,
312312
app_settings: ApplicationSettings,
313313
initialized_app: FastAPI,
314314
aws_allowed_ec2_instance_type_names_env: list[str],
@@ -322,17 +322,13 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
322322
instance_type_filters: Sequence[FilterTypeDef],
323323
):
324324
assert app_settings.AUTOSCALING_EC2_INSTANCES
325-
assert (
326-
mock_machines_buffer
327-
== app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
328-
)
329325
await auto_scale_cluster(
330326
app=initialized_app, auto_scaling_mode=DynamicAutoscaling()
331327
)
332328
await assert_autoscaled_dynamic_ec2_instances(
333329
ec2_client,
334330
expected_num_reservations=1,
335-
expected_num_instances=mock_machines_buffer,
331+
expected_num_instances=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
336332
expected_instance_type=cast(
337333
InstanceTypeType,
338334
next(
@@ -347,7 +343,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
347343
mock_rabbitmq_post_message,
348344
app_settings,
349345
initialized_app,
350-
instances_pending=mock_machines_buffer,
346+
instances_pending=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
351347
)
352348
mock_rabbitmq_post_message.reset_mock()
353349
# calling again should attach the new nodes to the reserve, but nothing should start
@@ -357,7 +353,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
357353
await assert_autoscaled_dynamic_ec2_instances(
358354
ec2_client,
359355
expected_num_reservations=1,
360-
expected_num_instances=mock_machines_buffer,
356+
expected_num_instances=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
361357
expected_instance_type=cast(
362358
InstanceTypeType,
363359
next(
@@ -376,14 +372,15 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
376372
mock_rabbitmq_post_message,
377373
app_settings,
378374
initialized_app,
379-
nodes_total=mock_machines_buffer,
380-
nodes_drained=mock_machines_buffer,
381-
instances_running=mock_machines_buffer,
375+
nodes_total=with_instances_machines_hot_buffer,
376+
nodes_drained=with_instances_machines_hot_buffer,
377+
instances_running=with_instances_machines_hot_buffer,
382378
cluster_total_resources={
383-
"cpus": mock_machines_buffer
379+
"cpus": app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
384380
* fake_node.description.resources.nano_cp_us
385381
/ 1e9,
386-
"ram": mock_machines_buffer * fake_node.description.resources.memory_bytes,
382+
"ram": app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
383+
* fake_node.description.resources.memory_bytes,
387384
},
388385
)
389386

@@ -395,7 +392,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
395392
await assert_autoscaled_dynamic_ec2_instances(
396393
ec2_client,
397394
expected_num_reservations=1,
398-
expected_num_instances=mock_machines_buffer,
395+
expected_num_instances=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
399396
expected_instance_type=cast(
400397
InstanceTypeType,
401398
next(

services/autoscaling/tests/unit/test_utils_auto_scaling_core.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_sort_empty_drained_nodes(
323323

324324

325325
def test_sort_drained_nodes(
326-
mock_machines_buffer: int,
326+
with_instances_machines_hot_buffer: EnvVarsDict,
327327
minimal_configuration: None,
328328
app_settings: ApplicationSettings,
329329
random_fake_available_instances: list[EC2InstanceType],
@@ -332,7 +332,9 @@ def test_sort_drained_nodes(
332332
):
333333
machine_buffer_type = get_machine_buffer_type(random_fake_available_instances)
334334
_NUM_DRAINED_NODES = 20
335-
_NUM_NODE_WITH_TYPE_BUFFER = 3 * mock_machines_buffer
335+
_NUM_NODE_WITH_TYPE_BUFFER = (
336+
3 * app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
337+
)
336338
_NUM_NODES_TERMINATING = 13
337339
fake_drained_nodes = []
338340
for _ in range(_NUM_DRAINED_NODES):
@@ -388,10 +390,6 @@ def test_sort_drained_nodes(
388390
app_settings, fake_drained_nodes, random_fake_available_instances
389391
)
390392
assert app_settings.AUTOSCALING_EC2_INSTANCES
391-
assert (
392-
mock_machines_buffer
393-
== app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
394-
)
395393
assert len(sorted_drained_nodes) == (
396394
_NUM_DRAINED_NODES
397395
+ _NUM_NODE_WITH_TYPE_BUFFER

0 commit comments

Comments
 (0)