Skip to content

Commit ecea27b

Browse files
author
Alex Wang
committed
Examples: Add wait for callback timeout test
1 parent 3850837 commit ecea27b

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

examples/examples-catalog.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@
188188
},
189189
"path": "./src/wait_for_callback/wait_for_callback_serdes.py"
190190
},
191+
{
192+
"name": "Wait For Callback Timeout",
193+
"description": "Usage of context.wait_for_callback() to wait for external system responses",
194+
"handler": "wait_for_callback_timeout.handler",
195+
"integration": true,
196+
"durableConfig": {
197+
"RetentionPeriodInDays": 7,
198+
"ExecutionTimeout": 300
199+
},
200+
"path": "./src/wait_for_callback/wait_for_callback_timeout.py"
201+
},
191202
{
192203
"name": "Wait For Callback Nested",
193204
"description": "Usage of context.wait_for_callback() to wait for external system responses",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Demonstrates waitForCallback timeout scenarios."""
2+
3+
from typing import Any
4+
5+
from aws_durable_execution_sdk_python.context import DurableContext
6+
from aws_durable_execution_sdk_python.execution import durable_execution
7+
from aws_durable_execution_sdk_python.config import Duration
8+
from aws_durable_execution_sdk_python.config import WaitForCallbackConfig
9+
10+
11+
@durable_execution
12+
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
13+
"""Handler demonstrating waitForCallback timeout."""
14+
15+
config = WaitForCallbackConfig(
16+
timeout=Duration.from_seconds(1), heartbeat_timeout=Duration.from_seconds(2)
17+
)
18+
19+
def submitter(_) -> None:
20+
"""Submitter succeeds but callback never completes."""
21+
return None
22+
23+
try:
24+
result: str = context.wait_for_callback(
25+
submitter,
26+
config=config,
27+
)
28+
29+
return {
30+
"callbackResult": result,
31+
"success": True,
32+
}
33+
except Exception as error:
34+
return {
35+
"success": False,
36+
"error": str(error),
37+
}

examples/template.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ Resources:
254254
DurableConfig:
255255
RetentionPeriodInDays: 7
256256
ExecutionTimeout: 300
257+
WaitForCallbackTimeout:
258+
Type: AWS::Serverless::Function
259+
Properties:
260+
CodeUri: build/
261+
Handler: wait_for_callback_timeout.handler
262+
Description: Usage of context.wait_for_callback() to wait for external system
263+
responses
264+
Role:
265+
Fn::GetAtt:
266+
- DurableFunctionRole
267+
- Arn
268+
DurableConfig:
269+
RetentionPeriodInDays: 7
270+
ExecutionTimeout: 300
257271
WaitForCallbackNested:
258272
Type: AWS::Serverless::Function
259273
Properties:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Tests for wait_for_callback_timeout."""
2+
3+
import pytest
4+
from aws_durable_execution_sdk_python.execution import InvocationStatus
5+
6+
from src.wait_for_callback import wait_for_callback_timeout
7+
from test.conftest import deserialize_operation_payload
8+
9+
10+
@pytest.mark.example
11+
@pytest.mark.durable_execution(
12+
handler=wait_for_callback_timeout.handler,
13+
lambda_function_name="Wait For Callback Timeout",
14+
)
15+
def test_handle_wait_for_callback_timeout_scenarios(durable_runner):
16+
"""Test waitForCallback timeout scenarios."""
17+
test_payload = {"test": "timeout-scenario"}
18+
19+
with durable_runner:
20+
execution_arn = durable_runner.run_async(input=test_payload, timeout=30)
21+
# Don't send callback - let it timeout
22+
result = durable_runner.wait_for_result(execution_arn=execution_arn)
23+
24+
# Handler catches the timeout error, so execution succeeds with error in result
25+
assert result.status is InvocationStatus.SUCCEEDED
26+
27+
result_data = deserialize_operation_payload(result.result)
28+
29+
assert result_data["success"] is False
30+
assert isinstance(result_data["error"], str)
31+
assert len(result_data["error"]) > 0
32+
assert "Callback timed out" == result_data["error"]

0 commit comments

Comments
 (0)