Skip to content

Commit fa9b163

Browse files
committed
improve test system
1 parent 5542eb8 commit fa9b163

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ def instance_type_filters(
245245
]
246246

247247

248+
@pytest.fixture
249+
def stopped_instance_type_filters(
250+
instance_type_filters: Sequence[FilterTypeDef],
251+
) -> Sequence[FilterTypeDef]:
252+
copied_filters = deepcopy(instance_type_filters)
253+
copied_filters[-1]["Values"] = ["stopped"]
254+
return copied_filters
255+
256+
248257
@dataclass(frozen=True)
249258
class _ScaleUpParams:
250259
imposed_instance_type: InstanceTypeType | None
@@ -2090,6 +2099,7 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
20902099
],
20912100
spied_cluster_analysis: MockType,
20922101
instance_type_filters: Sequence[FilterTypeDef],
2102+
stopped_instance_type_filters: Sequence[FilterTypeDef],
20932103
mock_find_node_with_name_returns_fake_node: mock.Mock,
20942104
mock_compute_node_used_resources: mock.Mock,
20952105
mock_docker_tag_node: mock.Mock,
@@ -2155,8 +2165,7 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21552165
)
21562166
await assert_autoscaled_dynamic_warm_pools_ec2_instances(
21572167
ec2_client,
2158-
expected_num_reservations=2,
2159-
check_reservation_index=1,
2168+
expected_num_reservations=1,
21602169
expected_num_instances=buffer_count,
21612170
expected_instance_type=cast(
21622171
InstanceTypeType,
@@ -2167,5 +2176,39 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21672176
expected_instance_state="stopped",
21682177
expected_additional_tag_keys=list(ec2_instance_custom_tags),
21692178
expected_pre_pulled_images=None,
2170-
instance_filters=None,
2179+
instance_filters=stopped_instance_type_filters,
2180+
)
2181+
2182+
# calling again should do nothing
2183+
await auto_scale_cluster(
2184+
app=initialized_app, auto_scaling_mode=DynamicAutoscaling()
2185+
)
2186+
await assert_autoscaled_dynamic_ec2_instances(
2187+
ec2_client,
2188+
expected_num_reservations=1,
2189+
expected_num_instances=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
2190+
expected_instance_type=cast(
2191+
InstanceTypeType,
2192+
next(
2193+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
2194+
),
2195+
),
2196+
expected_instance_state="running",
2197+
expected_additional_tag_keys=list(ec2_instance_custom_tags),
2198+
instance_filters=instance_type_filters,
2199+
)
2200+
await assert_autoscaled_dynamic_warm_pools_ec2_instances(
2201+
ec2_client,
2202+
expected_num_reservations=1,
2203+
expected_num_instances=buffer_count,
2204+
expected_instance_type=cast(
2205+
InstanceTypeType,
2206+
next(
2207+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
2208+
),
2209+
),
2210+
expected_instance_state="stopped",
2211+
expected_additional_tag_keys=list(ec2_instance_custom_tags),
2212+
expected_pre_pulled_images=None,
2213+
instance_filters=stopped_instance_type_filters,
21712214
)

0 commit comments

Comments
 (0)