Skip to content

Commit b7026fd

Browse files
committed
test ready
1 parent 851d7a7 commit b7026fd

File tree

1 file changed

+53
-7
lines changed

1 file changed

+53
-7
lines changed

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,42 +1794,50 @@ async def test__activate_drained_nodes_with_drained_node(
17941794

17951795

17961796
async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
1797+
patch_ec2_client_launch_instances_min_number_of_instances: mock.Mock,
17971798
minimal_configuration: None,
17981799
with_instances_machines_hot_buffer: EnvVarsDict,
17991800
ec2_client: EC2Client,
18001801
initialized_app: FastAPI,
18011802
app_settings: ApplicationSettings,
1802-
ec2_instances_allowed_types_with_only_1_buffered: dict[
1803-
InstanceTypeType, EC2InstanceBootSpecific
1804-
],
18051803
ec2_instance_custom_tags: dict[str, str],
18061804
buffer_count: int,
18071805
create_buffer_machines: Callable[
18081806
[int, InstanceTypeType, InstanceStateNameType, list[DockerGenericTag] | None],
18091807
Awaitable[list[str]],
18101808
],
18111809
spied_cluster_analysis: MockType,
1810+
instance_type_filters: Sequence[FilterTypeDef],
18121811
):
18131812
# pre-requisites
18141813
assert app_settings.AUTOSCALING_EC2_INSTANCES
18151814
assert app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER > 0
1815+
18161816
# we have nothing running now
18171817
all_instances = await ec2_client.describe_instances()
18181818
assert not all_instances["Reservations"]
18191819

1820-
# have a few warm buffers ready
1820+
# have a few warm buffers ready with the same type as the hot buffer machines
18211821
buffer_machines = await create_buffer_machines(
18221822
buffer_count,
1823-
next(iter(list(ec2_instances_allowed_types_with_only_1_buffered))),
1823+
cast(
1824+
InstanceTypeType,
1825+
next(
1826+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
1827+
),
1828+
),
18241829
"stopped",
18251830
None,
18261831
)
18271832
await assert_autoscaled_dynamic_warm_pools_ec2_instances(
18281833
ec2_client,
18291834
expected_num_reservations=1,
18301835
expected_num_instances=buffer_count,
1831-
expected_instance_type=next(
1832-
iter(ec2_instances_allowed_types_with_only_1_buffered)
1836+
expected_instance_type=cast(
1837+
InstanceTypeType,
1838+
next(
1839+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
1840+
),
18331841
),
18341842
expected_instance_state="stopped",
18351843
expected_additional_tag_keys=list(ec2_instance_custom_tags),
@@ -1841,6 +1849,7 @@ async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
18411849
await auto_scale_cluster(
18421850
app=initialized_app, auto_scaling_mode=DynamicAutoscaling()
18431851
)
1852+
# at analysis time, we had no machines running
18441853
analyzed_cluster = assert_cluster_state(
18451854
spied_cluster_analysis,
18461855
expected_calls=1,
@@ -1849,3 +1858,40 @@ async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
18491858
assert not analyzed_cluster.active_nodes
18501859
assert analyzed_cluster.buffer_ec2s
18511860
assert len(analyzed_cluster.buffer_ec2s) == len(buffer_machines)
1861+
1862+
# now we should have a warm buffer moved to the hot buffer
1863+
await assert_autoscaled_dynamic_ec2_instances(
1864+
ec2_client,
1865+
expected_num_reservations=1,
1866+
expected_num_instances=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
1867+
expected_instance_type=cast(
1868+
InstanceTypeType,
1869+
next(
1870+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
1871+
),
1872+
),
1873+
expected_instance_state="running",
1874+
expected_additional_tag_keys=list(ec2_instance_custom_tags),
1875+
instance_filters=instance_type_filters,
1876+
)
1877+
1878+
# let's autoscale again, to check the cluster analysis
1879+
await auto_scale_cluster(
1880+
app=initialized_app, auto_scaling_mode=DynamicAutoscaling()
1881+
)
1882+
# at analysis time, we had no machines running
1883+
analyzed_cluster = assert_cluster_state(
1884+
spied_cluster_analysis,
1885+
expected_calls=1,
1886+
expected_num_machines=app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
1887+
)
1888+
assert not analyzed_cluster.active_nodes
1889+
assert len(analyzed_cluster.buffer_ec2s) == max(
1890+
0,
1891+
buffer_count
1892+
- app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER,
1893+
)
1894+
assert (
1895+
len(analyzed_cluster.buffer_drained_nodes)
1896+
== app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
1897+
)

0 commit comments

Comments
 (0)