Skip to content

Commit 687cb77

Browse files
Alex Wangwangyb-A
authored andcommitted
examples: Add none response examples
1 parent 2116ab4 commit 687cb77

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

examples/examples-catalog.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@
334334
"ExecutionTimeout": 300
335335
},
336336
"path": "./src/handler_error/handler_error.py"
337+
},
338+
{
339+
"name": "None Results",
340+
"description": "Test handling of step operations with undefined result after replay.",
341+
"handler": "none_results.handler",
342+
"integration": true,
343+
"durableConfig": {
344+
"RetentionPeriodInDays": 7,
345+
"ExecutionTimeout": 300
346+
},
347+
"path": "./src/none_results/none_results.py"
337348
}
338349
]
339350
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Demonstrates handling of operations that return undefined values during replay."""
2+
3+
from typing import Any
4+
5+
from aws_durable_execution_sdk_python.context import (
6+
DurableContext,
7+
durable_with_child_context,
8+
)
9+
from aws_durable_execution_sdk_python.execution import durable_execution
10+
from aws_durable_execution_sdk_python.config import Duration
11+
12+
13+
@durable_with_child_context
14+
def parent_context(ctx: DurableContext) -> None:
15+
"""Parent context that returns None."""
16+
return None
17+
18+
19+
@durable_execution
20+
def handler(_event: Any, context: DurableContext) -> str:
21+
"""Handler demonstrating operations with undefined/None results."""
22+
context.step(
23+
lambda _: None,
24+
name="fetch-user",
25+
)
26+
27+
context.run_in_child_context(parent_context(), name="parent")
28+
29+
context.wait(Duration.from_seconds(1), name="wait")
30+
31+
return "result"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Tests for undefined_results."""
2+
3+
import pytest
4+
from aws_durable_execution_sdk_python.execution import InvocationStatus
5+
6+
from src.none_results import none_results
7+
from test.conftest import deserialize_operation_payload
8+
9+
10+
@pytest.mark.example
11+
@pytest.mark.durable_execution(
12+
handler=none_results.handler,
13+
lambda_function_name="None Results",
14+
)
15+
def test_handle_step_operations_with_undefined_result_after_replay(durable_runner):
16+
"""Test handling of step operations with undefined result after replay."""
17+
with durable_runner:
18+
result = durable_runner.run(input=None, timeout=10)
19+
20+
assert result.status is InvocationStatus.SUCCEEDED
21+
22+
# Verify execution completed successfully despite undefined operation results
23+
assert deserialize_operation_payload(result.result) == "result"
24+
25+
# Verify all operations were tracked even with undefined results
26+
operations = result.operations
27+
assert len(operations) == 3 # step + context + wait
28+
29+
# Verify step operation with undefined result
30+
step_ops = [
31+
op
32+
for op in operations
33+
if op.operation_type.value == "STEP" and op.name == "fetch-user"
34+
]
35+
assert len(step_ops) == 1
36+
step_op = step_ops[0]
37+
assert deserialize_operation_payload(step_op.result) is None
38+
39+
# Verify child context operation with undefined result
40+
context_ops = [
41+
op
42+
for op in operations
43+
if op.operation_type.value == "CONTEXT" and op.name == "parent"
44+
]
45+
assert len(context_ops) == 1
46+
context_op = context_ops[0]
47+
assert deserialize_operation_payload(context_op.result) is None
48+
49+
# Verify wait operation completed normally
50+
wait_op = operations[2]
51+
assert wait_op.operation_type.value == "WAIT"

0 commit comments

Comments
 (0)