Skip to content

Commit 60d538d

Browse files
committed
fix(examples):parallel_first_successful update to match sdk
1 parent 6bef3b2 commit 60d538d

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

packages/aws-durable-execution-sdk-python-examples/src/parallel/parallel_first_successful.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def handler(_event: Any, context: DurableContext) -> str:
2121
)
2222

2323
# Extract the first successful result
24-
first_result = (
25-
results.successful_results[0] if results.successful_results else "None"
26-
)
24+
successful = results.get_results()
25+
first_result = successful[0] if successful else "None"
2726
return f"First successful result: {first_result}"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)