File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed
Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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" ]
You can’t perform that action at this time.
0 commit comments