|
| 1 | +"""Tests for parallel first successful 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 | +from src.parallel import parallel_first_successful |
| 7 | +from test.conftest import deserialize_operation_payload |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.example |
| 11 | +@pytest.mark.durable_execution( |
| 12 | + handler=parallel_first_successful.handler, |
| 13 | + lambda_function_name="Parallel First Successful", |
| 14 | +) |
| 15 | +def test_parallel_first_successful(durable_runner): |
| 16 | + """Test parallel with first_successful completion strategy.""" |
| 17 | + with durable_runner: |
| 18 | + result = durable_runner.run(input="test", timeout=10) |
| 19 | + |
| 20 | + assert result.status is InvocationStatus.SUCCEEDED |
| 21 | + |
| 22 | + result_data = deserialize_operation_payload(result.result) |
| 23 | + # The handler returns a string like "First successful result: Task 1" |
| 24 | + assert result_data.startswith("First successful result: ") |
| 25 | + # The first successful result should be one of the tasks |
| 26 | + assert result_data in [ |
| 27 | + "First successful result: Task 1", |
| 28 | + "First successful result: Task 2", |
| 29 | + "First successful result: Task 3", |
| 30 | + ] |
| 31 | + |
| 32 | + # Get the parallel operation |
| 33 | + parallel_op = result.get_context("first_successful_parallel") |
| 34 | + assert parallel_op is not None |
| 35 | + assert parallel_op.status is OperationStatus.SUCCEEDED |
| 36 | + |
| 37 | + # Verify child operations exist (3 branches) |
| 38 | + assert len(parallel_op.child_operations) == 3 |
| 39 | + |
| 40 | + # At least one child should have succeeded |
| 41 | + succeeded = [ |
| 42 | + op |
| 43 | + for op in parallel_op.child_operations |
| 44 | + if op.status is OperationStatus.SUCCEEDED |
| 45 | + ] |
| 46 | + assert len(succeeded) >= 1 |
0 commit comments