Skip to content

Commit f3a42c9

Browse files
committed
test(live): assert capacity-unit fulfilment + template-aware count
Replace the relaxed `len(machine_ids) >= 1` assertions in the four live test files with a two-part check: 1. Capacity-unit fulfilment: assert fulfilled_units >= target_units using the new fields from the provider response (status_response["requests"][0]["target_units"] / ["fulfilled_units"]). When the fields are absent (older build) falls back to capacity and len(machine_ids) so existing runs are unaffected. 2. Template-aware instance count: if template_uses_weighted_capacity() returns True, assert at least one instance was launched (weighted capacity units can fulfil with fewer physical instances); otherwise assert exactly `capacity` instances were provisioned. Files changed: test_sdk_onaws.py, test_mcp_onaws.py, test_cleanup_e2e_onaws.py, test_onaws.py (provide_release_control_loop).
1 parent 4b3502a commit f3a42c9

4 files changed

Lines changed: 82 additions & 23 deletions

File tree

tests/providers/aws/live/test_cleanup_e2e_onaws.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,26 @@ async def _run_cleanup_verification(
467467

468468
# 3. Assert instances provisioned
469469
machine_ids = _extract_machine_ids(status_response)
470-
# Weighted templates can fulfill capacity with fewer instances (AWS
471-
# WeightedCapacity). The COMPLETED status above already proves the fleet
472-
# reached its target capacity; assert only that at least one instance was
473-
# launched.
474-
assert len(machine_ids) >= 1, (
475-
f"Expected at least one machine after complete status, got: {machine_ids}"
470+
471+
# Capacity-unit fulfilment check from provider response fields.
472+
# target_units / fulfilled_units reflect capacity units for weighted fleets
473+
# and instance count for unweighted templates (1 unit == 1 instance).
474+
_req0 = status_response.get("requests", [{}])[0] if isinstance(status_response, dict) else {}
475+
target_units = _req0.get("target_units") or capacity
476+
fulfilled_units = _req0.get("fulfilled_units") or len(machine_ids)
477+
assert fulfilled_units >= target_units, (
478+
f"Fleet not fully fulfilled: fulfilled={fulfilled_units}, target={target_units}"
476479
)
477-
_ = capacity # retained for log context
480+
481+
# Template-aware instance count sanity check.
482+
if scenarios.template_uses_weighted_capacity(test_case):
483+
assert len(machine_ids) >= 1, (
484+
f"Expected at least 1 machine (weighted template), got: {machine_ids}"
485+
)
486+
else:
487+
assert len(machine_ids) == capacity, (
488+
f"Expected {capacity} machines (unweighted template), got {len(machine_ids)}: {machine_ids}"
489+
)
478490

479491
returned_id = status_response.get("requests", [{}])[0].get("request_id") or status_response.get(
480492
"requests", [{}]

tests/providers/aws/live/test_mcp_onaws.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,27 @@ async def _run_full_cycle_mcp(mcp_server, test_case: dict, tracked_request_ids:
343343
)
344344

345345
machine_ids = _extract_machine_ids(status_result)
346-
# Weighted templates (vmTypes with weight > 1) launch fewer instances than the
347-
# requested capacity units (AWS WeightedCapacity semantics). Assert that the
348-
# fleet was fulfilled (status == complete already proves this) and that at
349-
# least one instance is healthy. For unweighted templates instance count
350-
# equals capacity, but the strict equality is enforced by the provider via
351-
# the COMPLETED gate, not by this assertion.
352-
assert len(machine_ids) >= 1, (
353-
f"Expected at least one machine after complete status, got: {machine_ids}"
346+
347+
# Capacity-unit fulfilment check from provider response fields.
348+
# target_units / fulfilled_units reflect capacity units for weighted fleets
349+
# and instance count for unweighted templates (1 unit == 1 instance).
350+
_req0 = status_result.get("requests", [{}])[0] if isinstance(status_result, dict) else {}
351+
target_units = _req0.get("target_units") or capacity
352+
fulfilled_units = _req0.get("fulfilled_units") or len(machine_ids)
353+
assert fulfilled_units >= target_units, (
354+
f"Fleet not fully fulfilled: fulfilled={fulfilled_units}, target={target_units}"
354355
)
355356

357+
# Template-aware instance count sanity check.
358+
if scenarios.template_uses_weighted_capacity(test_case):
359+
assert len(machine_ids) >= 1, (
360+
f"Expected at least 1 machine (weighted template), got: {machine_ids}"
361+
)
362+
else:
363+
assert len(machine_ids) == capacity, (
364+
f"Expected {capacity} machines (unweighted template), got {len(machine_ids)}: {machine_ids}"
365+
)
366+
356367
for machine_id in machine_ids:
357368
state = get_instance_state(machine_id)
358369
assert state["exists"], f"Instance {machine_id} not found in AWS"

tests/providers/aws/live/test_onaws.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,31 @@ def provide_release_control_loop(hfm, template_json, capacity_to_request, test_c
14821482

14831483
_check_all_ec2_hosts_are_being_provisioned(status_response)
14841484

1485+
# Capacity-unit fulfilment check from provider response fields.
1486+
# target_units / fulfilled_units reflect capacity units for weighted fleets
1487+
# and instance count for unweighted templates (1 unit == 1 instance).
1488+
_req0 = status_response.get("requests", [{}])[0] if isinstance(status_response, dict) else {}
1489+
_machine_ids_for_check = [
1490+
m.get("machineId") or m.get("machine_id")
1491+
for m in _req0.get("machines", [])
1492+
if m.get("machineId") or m.get("machine_id")
1493+
]
1494+
_target_units = _req0.get("target_units") or capacity_to_request
1495+
_fulfilled_units = _req0.get("fulfilled_units") or len(_machine_ids_for_check)
1496+
assert _fulfilled_units >= _target_units, (
1497+
f"Fleet not fully fulfilled: fulfilled={_fulfilled_units}, target={_target_units}"
1498+
)
1499+
# Template-aware instance count sanity check.
1500+
if test_case and scenarios.template_uses_weighted_capacity(test_case):
1501+
assert len(_machine_ids_for_check) >= 1, (
1502+
f"Expected at least 1 machine (weighted template), got: {_machine_ids_for_check}"
1503+
)
1504+
else:
1505+
assert len(_machine_ids_for_check) == capacity_to_request, (
1506+
f"Expected {capacity_to_request} machines (unweighted template), "
1507+
f"got {len(_machine_ids_for_check)}: {_machine_ids_for_check}"
1508+
)
1509+
14851510
# Validate instance attributes against template
14861511
log.info("Starting instance attribute validation against template")
14871512
attribute_validation_passed = validate_random_instance_attributes(

tests/providers/aws/live/test_sdk_onaws.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,27 @@ async def _run_full_cycle(sdk, test_case: dict, tracked_request_ids: list[str])
310310
)
311311

312312
machine_ids = _extract_machine_ids(status_response)
313-
# Weighted templates (vmTypes with weight > 1) launch fewer instances than the
314-
# requested capacity units (AWS WeightedCapacity semantics). Assert that the
315-
# fleet was fulfilled (status == complete already proves this) and that at
316-
# least one instance is healthy. For unweighted templates instance count
317-
# equals capacity, but the strict equality is enforced by the provider via
318-
# the COMPLETED gate, not by this assertion.
319-
assert len(machine_ids) >= 1, (
320-
f"Expected at least one machine after complete status, got: {machine_ids}"
313+
314+
# Capacity-unit fulfilment check from provider response fields.
315+
# target_units / fulfilled_units reflect capacity units for weighted fleets
316+
# and instance count for unweighted templates (1 unit == 1 instance).
317+
_req0 = status_response.get("requests", [{}])[0] if isinstance(status_response, dict) else {}
318+
target_units = _req0.get("target_units") or capacity
319+
fulfilled_units = _req0.get("fulfilled_units") or len(machine_ids)
320+
assert fulfilled_units >= target_units, (
321+
f"Fleet not fully fulfilled: fulfilled={fulfilled_units}, target={target_units}"
321322
)
322323

324+
# Template-aware instance count sanity check.
325+
if scenarios.template_uses_weighted_capacity(test_case):
326+
assert len(machine_ids) >= 1, (
327+
f"Expected at least 1 machine (weighted template), got: {machine_ids}"
328+
)
329+
else:
330+
assert len(machine_ids) == capacity, (
331+
f"Expected {capacity} machines (unweighted template), got {len(machine_ids)}: {machine_ids}"
332+
)
333+
323334
for machine_id in machine_ids:
324335
state = get_instance_state(machine_id)
325336
assert state["exists"], f"Instance {machine_id} not found in AWS"

0 commit comments

Comments
 (0)