Skip to content

Commit dd4c390

Browse files
committed
fix(test/cleanup): mock _fleet_has_no_remaining_instances on partial-return tests
EC2Fleet partial path now calls _fleet_has_no_remaining_instances, which runs _collect_with_next_token in a NextToken loop against a MagicMock ec2_client. MagicMock.get(...) returns a truthy MagicMock for the NextToken key, so the loop never terminates — the test hung indefinitely. SpotFleet partial path has the same defensive call. Its retry-based variant returns a MagicMock whose .get('ActiveInstances', []) yields an empty iterator, which falsely flags the fleet as empty and triggers an unintended launch-template cleanup, failing the assertion. Patch _fleet_has_no_remaining_instances to return False on both partial-return tests so the production code skips the new defensive check and the original partial-return semantic is exercised.
1 parent 5f90f71 commit dd4c390

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

tests/providers/aws/unit/infrastructure/handlers/test_cleanup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ def test_partial_return_does_not_trigger_lt_cleanup(self):
310310
with (
311311
patch.object(handler._fleet_release_manager, "_delete_fleet") as mock_delete_fleet,
312312
patch.object(handler, "_delete_orb_launch_template") as mock_delete_lt,
313+
patch.object(
314+
handler._fleet_release_manager,
315+
"_fleet_has_no_remaining_instances",
316+
return_value=False,
317+
),
313318
):
314319
handler._release_hosts_for_single_ec2_fleet(
315320
"fleet-123",
@@ -390,7 +395,14 @@ def test_partial_return_does_not_trigger_lt_cleanup(self):
390395
config_port = _make_config_port()
391396
handler = _make_spot_fleet_handler(config_port=config_port)
392397

393-
with patch.object(handler, "_delete_orb_launch_template") as mock_delete_lt:
398+
with (
399+
patch.object(handler, "_delete_orb_launch_template") as mock_delete_lt,
400+
patch.object(
401+
handler._release_manager,
402+
"_fleet_has_no_remaining_instances",
403+
return_value=False,
404+
),
405+
):
394406
handler._release_hosts_for_single_spot_fleet(
395407
"sfr-123",
396408
["i-1"],

0 commit comments

Comments
 (0)