|
| 1 | +"""Tests for comprehensive_operations.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from aws_durable_execution_sdk_python.execution import InvocationStatus |
| 5 | + |
| 6 | +from src.comprehensive_operations import comprehensive_operations |
| 7 | +from test.conftest import deserialize_operation_payload |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.example |
| 11 | +@pytest.mark.durable_execution( |
| 12 | + handler=comprehensive_operations.handler, |
| 13 | + lambda_function_name="Comprehensive Operations", |
| 14 | +) |
| 15 | +def test_execute_all_operations_successfully(durable_runner): |
| 16 | + """Test that all operations execute successfully.""" |
| 17 | + with durable_runner: |
| 18 | + result = durable_runner.run(input={"message": "test"}, timeout=30) |
| 19 | + |
| 20 | + assert result.status is InvocationStatus.SUCCEEDED |
| 21 | + |
| 22 | + result_data = deserialize_operation_payload(result.result) |
| 23 | + |
| 24 | + assert result_data["step1"] == "Step 1 completed successfully" |
| 25 | + assert result_data["waitCompleted"] is True |
| 26 | + |
| 27 | + # verify map results |
| 28 | + map_results = result_data["mapResults"] |
| 29 | + assert len(map_results["all"]) == 5 |
| 30 | + assert [item["result"] for item in map_results["all"]] == [1, 2, 3, 4, 5] |
| 31 | + assert map_results["completionReason"] == "ALL_COMPLETED" |
| 32 | + |
| 33 | + # verify parallel results |
| 34 | + parallel_results = result_data["parallelResults"] |
| 35 | + assert len(parallel_results["all"]) == 3 |
| 36 | + assert [item["result"] for item in parallel_results["all"]] == [ |
| 37 | + "apple", |
| 38 | + "banana", |
| 39 | + "orange", |
| 40 | + ] |
| 41 | + assert parallel_results["completionReason"] == "ALL_COMPLETED" |
| 42 | + |
| 43 | + # Get all operations including nested ones |
| 44 | + all_ops = result.get_all_operations() |
| 45 | + |
| 46 | + # Verify step1 operation |
| 47 | + step1_ops = [ |
| 48 | + op for op in all_ops if op.operation_type.value == "STEP" and op.name == "step1" |
| 49 | + ] |
| 50 | + assert len(step1_ops) == 1 |
| 51 | + step1_op = step1_ops[0] |
| 52 | + assert ( |
| 53 | + deserialize_operation_payload(step1_op.result) |
| 54 | + == "Step 1 completed successfully" |
| 55 | + ) |
| 56 | + |
| 57 | + # Verify wait operation (should be at index 1) |
| 58 | + wait_op = result.operations[1] |
| 59 | + assert wait_op.operation_type.value == "WAIT" |
| 60 | + |
| 61 | + # Verify individual map step operations exist with correct names |
| 62 | + for i in range(5): |
| 63 | + map_step_ops = [ |
| 64 | + op |
| 65 | + for op in all_ops |
| 66 | + if op.operation_type.value == "STEP" and op.name == f"map-step-{i}" |
| 67 | + ] |
| 68 | + assert len(map_step_ops) == 1 |
| 69 | + assert deserialize_operation_payload(map_step_ops[0].result) == i + 1 |
| 70 | + |
| 71 | + # Verify individual parallel step operations exist |
| 72 | + fruit_step_1_ops = [ |
| 73 | + op |
| 74 | + for op in all_ops |
| 75 | + if op.operation_type.value == "STEP" and op.name == "fruit-step-1" |
| 76 | + ] |
| 77 | + assert len(fruit_step_1_ops) == 1 |
| 78 | + assert deserialize_operation_payload(fruit_step_1_ops[0].result) == "apple" |
| 79 | + |
| 80 | + fruit_step_2_ops = [ |
| 81 | + op |
| 82 | + for op in all_ops |
| 83 | + if op.operation_type.value == "STEP" and op.name == "fruit-step-2" |
| 84 | + ] |
| 85 | + assert len(fruit_step_2_ops) == 1 |
| 86 | + assert deserialize_operation_payload(fruit_step_2_ops[0].result) == "banana" |
| 87 | + |
| 88 | + fruit_step_3_ops = [ |
| 89 | + op |
| 90 | + for op in all_ops |
| 91 | + if op.operation_type.value == "STEP" and op.name == "fruit-step-3" |
| 92 | + ] |
| 93 | + assert len(fruit_step_3_ops) == 1 |
| 94 | + assert deserialize_operation_payload(fruit_step_3_ops[0].result) == "orange" |
0 commit comments