@@ -2165,8 +2165,9 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21652165 DOCKER_TASK_EC2_INSTANCE_TYPE_PLACEMENT_CONSTRAINT_KEY : f"{ hot_buffer_instance_type } "
21662166 }
21672167 fake_attached_node_base .spec .labels |= expected_docker_node_tags | {
2168- _OSPARC_SERVICE_READY_LABEL_KEY : "true "
2168+ _OSPARC_SERVICE_READY_LABEL_KEY : "false "
21692169 }
2170+ fake_attached_node_base .status .state = NodeState .ready
21702171 fake_hot_buffer_nodes = []
21712172 for i in range (num_hot_buffer ):
21722173 node = fake_attached_node_base .model_copy (deep = True )
@@ -2182,6 +2183,7 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21822183 autospec = True ,
21832184 return_value = fake_hot_buffer_nodes ,
21842185 )
2186+
21852187 await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
21862188 await assert_autoscaled_dynamic_ec2_instances (
21872189 ec2_client ,
@@ -2260,11 +2262,13 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22602262 expected_num_instances = 1 ,
22612263 )
22622264 await create_services_batch (scale_up_params )
2263- # this should trigger usage of the hot buffer and the warm buffers should remain stopped
2265+
2266+ # this should trigger usage of the hot buffer and the warm buffers should replace the hot buffer
22642267 await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
22652268 await assert_autoscaled_dynamic_ec2_instances (
22662269 ec2_client ,
2267- expected_num_reservations = 1 ,
2270+ expected_num_reservations = 2 ,
2271+ check_reservation_index = 0 ,
22682272 expected_num_instances = num_hot_buffer ,
22692273 expected_instance_type = hot_buffer_instance_type ,
22702274 expected_instance_state = "running" ,
@@ -2273,24 +2277,13 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22732277 )
22742278 await assert_autoscaled_dynamic_warm_pools_ec2_instances (
22752279 ec2_client ,
2276- expected_num_reservations = 1 ,
2277- expected_num_instances = buffer_count ,
2278- expected_instance_type = hot_buffer_instance_type ,
2279- expected_instance_state = "stopped" ,
2280- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2281- expected_pre_pulled_images = None ,
2282- instance_filters = stopped_instance_type_filters ,
2283- )
2284-
2285- # this should trigger replacement TAG_PREFIX: staging-hotfix-github of the hot buffer by 1 warm buffer
2286- await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2287- await assert_autoscaled_dynamic_ec2_instances (
2288- ec2_client ,
2289- expected_num_reservations = 1 ,
2290- expected_num_instances = num_hot_buffer + 1 ,
2280+ expected_num_reservations = 2 ,
2281+ check_reservation_index = 1 ,
2282+ expected_num_instances = 1 ,
22912283 expected_instance_type = hot_buffer_instance_type ,
22922284 expected_instance_state = "running" ,
22932285 expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2286+ expected_pre_pulled_images = None ,
22942287 instance_filters = instance_type_filters ,
22952288 )
22962289 await assert_autoscaled_dynamic_warm_pools_ec2_instances (
@@ -2303,3 +2296,32 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
23032296 expected_pre_pulled_images = None ,
23042297 instance_filters = stopped_instance_type_filters ,
23052298 )
2299+ # simulate one of the hot buffer is not drained anymore and took the pending service
2300+ random_fake_node = random .choice (fake_hot_buffer_nodes )
2301+ random_fake_node .spec .labels [_OSPARC_SERVICE_READY_LABEL_KEY ] = "true"
2302+ random_fake_node .spec .labels [
2303+ _OSPARC_SERVICES_READY_DATETIME_LABEL_KEY
2304+ ] = arrow .utcnow ().isoformat ()
2305+ random_fake_node .spec .availability = Availability .active
2306+ # simulate the fact that the warm buffer that just started is not yet visible
2307+ mock_find_node_with_name_returns_fake_node .return_value = None
2308+
2309+ # get the new analysis
2310+ await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2311+ spied_cluster = assert_cluster_state (
2312+ spied_cluster_analysis , expected_calls = 2 , expected_num_machines = 6
2313+ )
2314+ assert len (spied_cluster .buffer_drained_nodes ) == num_hot_buffer - 1
2315+ assert len (spied_cluster .buffer_ec2s ) == buffer_count - 1
2316+ assert len (spied_cluster .active_nodes ) == 1
2317+ assert len (spied_cluster .pending_ec2s ) == 1
2318+
2319+ # running it again shall do nothing
2320+ await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2321+ spied_cluster = assert_cluster_state (
2322+ spied_cluster_analysis , expected_calls = 1 , expected_num_machines = 6
2323+ )
2324+ assert len (spied_cluster .buffer_drained_nodes ) == num_hot_buffer - 1
2325+ assert len (spied_cluster .buffer_ec2s ) == buffer_count - 1
2326+ assert len (spied_cluster .active_nodes ) == 1
2327+ assert len (spied_cluster .pending_ec2s ) == 1
0 commit comments