@@ -2165,8 +2165,9 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
2165
2165
DOCKER_TASK_EC2_INSTANCE_TYPE_PLACEMENT_CONSTRAINT_KEY : f"{ hot_buffer_instance_type } "
2166
2166
}
2167
2167
fake_attached_node_base .spec .labels |= expected_docker_node_tags | {
2168
- _OSPARC_SERVICE_READY_LABEL_KEY : "true "
2168
+ _OSPARC_SERVICE_READY_LABEL_KEY : "false "
2169
2169
}
2170
+ fake_attached_node_base .status .state = NodeState .ready
2170
2171
fake_hot_buffer_nodes = []
2171
2172
for i in range (num_hot_buffer ):
2172
2173
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
2182
2183
autospec = True ,
2183
2184
return_value = fake_hot_buffer_nodes ,
2184
2185
)
2186
+
2185
2187
await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2186
2188
await assert_autoscaled_dynamic_ec2_instances (
2187
2189
ec2_client ,
@@ -2260,11 +2262,13 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
2260
2262
expected_num_instances = 1 ,
2261
2263
)
2262
2264
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
2264
2267
await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2265
2268
await assert_autoscaled_dynamic_ec2_instances (
2266
2269
ec2_client ,
2267
- expected_num_reservations = 1 ,
2270
+ expected_num_reservations = 2 ,
2271
+ check_reservation_index = 0 ,
2268
2272
expected_num_instances = num_hot_buffer ,
2269
2273
expected_instance_type = hot_buffer_instance_type ,
2270
2274
expected_instance_state = "running" ,
@@ -2273,24 +2277,13 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
2273
2277
)
2274
2278
await assert_autoscaled_dynamic_warm_pools_ec2_instances (
2275
2279
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 ,
2291
2283
expected_instance_type = hot_buffer_instance_type ,
2292
2284
expected_instance_state = "running" ,
2293
2285
expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2286
+ expected_pre_pulled_images = None ,
2294
2287
instance_filters = instance_type_filters ,
2295
2288
)
2296
2289
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
2303
2296
expected_pre_pulled_images = None ,
2304
2297
instance_filters = stopped_instance_type_filters ,
2305
2298
)
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