|
| 1 | +"""Tests for map_operations example.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from aws_durable_execution_sdk_python.execution import InvocationStatus |
| 5 | +from aws_durable_execution_sdk_python.lambda_service import OperationStatus |
| 6 | + |
| 7 | +from src.map import map_operations_flat |
| 8 | +from test.conftest import deserialize_operation_payload |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.example |
| 12 | +@pytest.mark.durable_execution( |
| 13 | + handler=map_operations_flat.handler, |
| 14 | + lambda_function_name="Map Operations Flat", |
| 15 | +) |
| 16 | +def test_map_operations_flat(durable_runner): |
| 17 | + """Test map_operations example using context.map().""" |
| 18 | + with durable_runner: |
| 19 | + result = durable_runner.run(input="test", timeout=10) |
| 20 | + |
| 21 | + assert result.status is InvocationStatus.SUCCEEDED |
| 22 | + assert deserialize_operation_payload(result.result) == [2, 4, 6, 8, 10] |
| 23 | + |
| 24 | + # Get the map operation (CONTEXT type with MAP subtype) |
| 25 | + map_op = result.get_context("map_operation") |
| 26 | + assert map_op is not None |
| 27 | + assert map_op.status is OperationStatus.SUCCEEDED |
| 28 | + |
| 29 | + # Verify all five child operations exist |
| 30 | + assert len(map_op.child_operations) == 5 |
| 31 | + |
| 32 | + # Verify child step operation names |
| 33 | + child_names = {op.name for op in map_op.child_operations} |
| 34 | + expected_names = {f"map_item_{i}" for i in range(5)} |
| 35 | + assert child_names == expected_names |
| 36 | + |
| 37 | + # Verify all children succeeded |
| 38 | + for child in map_op.child_operations: |
| 39 | + assert child.status is OperationStatus.SUCCEEDED |
0 commit comments