@@ -1066,8 +1066,9 @@ def test_handler(event: Any, context: DurableContext) -> dict:
10661066 # Make the service client checkpoint call fail with CheckpointError
10671067 mock_client .checkpoint .side_effect = failing_checkpoint
10681068
1069- with pytest .raises (CheckpointError , match = "Background checkpoint failed" ):
1070- test_handler (invocation_input , lambda_context )
1069+ response = test_handler (invocation_input , lambda_context )
1070+ assert response ["Status" ] == InvocationStatus .FAILED .value
1071+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
10711072
10721073
10731074# endregion durable_execution
@@ -1120,16 +1121,13 @@ def slow_background():
11201121 "aws_durable_execution_sdk_python.state.ExecutionState.checkpoint_batches_forever" ,
11211122 side_effect = slow_background ,
11221123 ):
1123- with pytest . raises ( CheckpointError , match = "Checkpoint system failed" ):
1124- test_handler ( invocation_input , lambda_context )
1125-
1124+ response = test_handler ( invocation_input , lambda_context )
1125+ assert response [ "Status" ] == InvocationStatus . FAILED . value
1126+ assert response [ "Error" ][ "ErrorType" ] == "CheckpointError"
11261127
1127- def test_durable_execution_checkpoint_invocation_error_stops_background ():
1128- """Test that CheckpointError handler stops background checkpointing.
11291128
1130- When user code raises CheckpointError, the handler should stop the background
1131- thread before re-raising to terminate the Lambda.
1132- """
1129+ def test_durable_execution_checkpoint_invocation_error_retries ():
1130+ """Test that CheckpointError with INVOCATION category re-raises to trigger Lambda retry."""
11331131 mock_client = Mock (spec = DurableServiceClient )
11341132
11351133 @durable_execution
@@ -1171,13 +1169,12 @@ def slow_background():
11711169 "aws_durable_execution_sdk_python.state.ExecutionState.checkpoint_batches_forever" ,
11721170 side_effect = slow_background ,
11731171 ):
1174- response = test_handler (invocation_input , lambda_context )
1175- assert response ["Status" ] == InvocationStatus .FAILED .value
1176- assert response ["Error" ]["ErrorType" ] == "CheckpointError"
1172+ with pytest .raises (CheckpointError , match = "Checkpoint system failed" ):
1173+ test_handler (invocation_input , lambda_context )
11771174
11781175
1179- def test_durable_execution_background_thread_execution_error_retries ():
1180- """Test that background thread Execution errors are retried (re-raised )."""
1176+ def test_durable_execution_background_thread_execution_error_returns_failed ():
1177+ """Test that background thread Execution errors return FAILED (permanent, no retry )."""
11811178 mock_client = Mock (spec = DurableServiceClient )
11821179
11831180 def failing_checkpoint (* args , ** kwargs ):
@@ -1215,12 +1212,13 @@ def test_handler(event: Any, context: DurableContext) -> dict:
12151212
12161213 mock_client .checkpoint .side_effect = failing_checkpoint
12171214
1218- with pytest .raises (CheckpointError , match = "Background checkpoint failed" ):
1219- test_handler (invocation_input , lambda_context )
1215+ response = test_handler (invocation_input , lambda_context )
1216+ assert response ["Status" ] == InvocationStatus .FAILED .value
1217+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
12201218
12211219
1222- def test_durable_execution_background_thread_invocation_error_returns_failed ():
1223- """Test that background thread Invocation errors return FAILED status ."""
1220+ def test_durable_execution_background_thread_invocation_error_retries ():
1221+ """Test that background thread Invocation errors re-raise to trigger Lambda retry ."""
12241222 mock_client = Mock (spec = DurableServiceClient )
12251223
12261224 def failing_checkpoint (* args , ** kwargs ):
@@ -1258,13 +1256,12 @@ def test_handler(event: Any, context: DurableContext) -> dict:
12581256
12591257 mock_client .checkpoint .side_effect = failing_checkpoint
12601258
1261- response = test_handler (invocation_input , lambda_context )
1262- assert response ["Status" ] == InvocationStatus .FAILED .value
1263- assert response ["Error" ]["ErrorType" ] == "CheckpointError"
1259+ with pytest .raises (CheckpointError , match = "Background checkpoint failed" ):
1260+ test_handler (invocation_input , lambda_context )
12641261
12651262
1266- def test_durable_execution_final_success_checkpoint_execution_error_retries ():
1267- """Test that execution errors on final success checkpoint trigger retry."""
1263+ def test_durable_execution_final_success_checkpoint_execution_error_returns_failed ():
1264+ """Test that execution errors on final success checkpoint return FAILED (permanent, no retry) ."""
12681265 mock_client = Mock (spec = DurableServiceClient )
12691266
12701267 def failing_final_checkpoint (* args , ** kwargs ):
@@ -1303,12 +1300,13 @@ def test_handler(event: Any, context: DurableContext) -> dict:
13031300
13041301 mock_client .checkpoint .side_effect = failing_final_checkpoint
13051302
1306- with pytest .raises (CheckpointError , match = "Final checkpoint failed" ):
1307- test_handler (invocation_input , lambda_context )
1303+ response = test_handler (invocation_input , lambda_context )
1304+ assert response ["Status" ] == InvocationStatus .FAILED .value
1305+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
13081306
13091307
1310- def test_durable_execution_final_success_checkpoint_invocation_error_returns_failed ():
1311- """Test that invocation errors on final success checkpoint return FAILED ."""
1308+ def test_durable_execution_final_success_checkpoint_invocation_error_retries ():
1309+ """Test that invocation errors on final success checkpoint re-raise to trigger Lambda retry ."""
13121310 mock_client = Mock (spec = DurableServiceClient )
13131311
13141312 def failing_final_checkpoint (* args , ** kwargs ):
@@ -1348,14 +1346,12 @@ def test_handler(event: Any, context: DurableContext) -> dict:
13481346
13491347 mock_client .checkpoint .side_effect = failing_final_checkpoint
13501348
1351- response = test_handler (invocation_input , lambda_context )
1352- assert response ["Status" ] == InvocationStatus .FAILED .value
1353- assert response ["Error" ]["ErrorType" ] == "CheckpointError"
1354- assert response ["Error" ]["ErrorMessage" ] == "Final checkpoint failed"
1349+ with pytest .raises (CheckpointError , match = "Final checkpoint failed" ):
1350+ test_handler (invocation_input , lambda_context )
13551351
13561352
1357- def test_durable_execution_final_failure_checkpoint_execution_error_retries ():
1358- """Test that execution errors on final failure checkpoint trigger retry."""
1353+ def test_durable_execution_final_failure_checkpoint_execution_error_returns_failed ():
1354+ """Test that execution errors on final failure checkpoint return FAILED (permanent, no retry) ."""
13591355 mock_client = Mock (spec = DurableServiceClient )
13601356
13611357 def failing_final_checkpoint (* args , ** kwargs ):
@@ -1396,12 +1392,13 @@ def test_handler(event: Any, context: DurableContext) -> dict:
13961392
13971393 mock_client .checkpoint .side_effect = failing_final_checkpoint
13981394
1399- with pytest .raises (CheckpointError , match = "Final checkpoint failed" ):
1400- test_handler (invocation_input , lambda_context )
1395+ response = test_handler (invocation_input , lambda_context )
1396+ assert response ["Status" ] == InvocationStatus .FAILED .value
1397+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
14011398
14021399
1403- def test_durable_execution_final_failure_checkpoint_invocation_error_returns_failed ():
1404- """Test that invocation errors on final failure checkpoint return FAILED ."""
1400+ def test_durable_execution_final_failure_checkpoint_invocation_error_retries ():
1401+ """Test that invocation errors on final failure checkpoint re-raise to trigger Lambda retry ."""
14051402 mock_client = Mock (spec = DurableServiceClient )
14061403
14071404 def failing_final_checkpoint (* args , ** kwargs ):
@@ -1442,10 +1439,8 @@ def test_handler(event: Any, context: DurableContext) -> dict:
14421439
14431440 mock_client .checkpoint .side_effect = failing_final_checkpoint
14441441
1445- response = test_handler (invocation_input , lambda_context )
1446- assert response ["Status" ] == InvocationStatus .FAILED .value
1447- assert response ["Error" ]["ErrorType" ] == "CheckpointError"
1448- assert response ["Error" ]["ErrorMessage" ] == "Final checkpoint failed"
1442+ with pytest .raises (CheckpointError , match = "Final checkpoint failed" ):
1443+ test_handler (invocation_input , lambda_context )
14491444
14501445
14511446def test_durable_handler_background_thread_failure_on_succeed_checkpoint ():
@@ -1809,8 +1804,9 @@ def test_handler(event: Any, context: DurableContext) -> dict:
18091804 mock_client .checkpoint .side_effect = failing_checkpoint
18101805
18111806 with patch ("aws_durable_execution_sdk_python.execution.logger" , mock_logger ):
1812- with pytest .raises (CheckpointError ):
1813- test_handler (invocation_input , lambda_context )
1807+ response = test_handler (invocation_input , lambda_context )
1808+ assert response ["Status" ] == InvocationStatus .FAILED .value
1809+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
18141810
18151811 mock_logger .exception .assert_called_once ()
18161812 call_args = mock_logger .exception .call_args
@@ -1922,8 +1918,9 @@ def test_handler(event: Any, context: DurableContext) -> dict:
19221918 lambda_context .tenant_id = None
19231919
19241920 with patch ("aws_durable_execution_sdk_python.execution.logger" , mock_logger ):
1925- with pytest .raises (CheckpointError ):
1926- test_handler (invocation_input , lambda_context )
1921+ response = test_handler (invocation_input , lambda_context )
1922+ assert response ["Status" ] == InvocationStatus .FAILED .value
1923+ assert response ["Error" ]["ErrorType" ] == "CheckpointError"
19271924
19281925 mock_logger .exception .assert_called_once ()
19291926 call_args = mock_logger .exception .call_args
0 commit comments