Skip to content

Commit fa85725

Browse files
authored
fix: retry transient get durable execution not found (#512)
1 parent 21892af commit fa85725

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

  • packages/aws-durable-execution-sdk-python-testing

packages/aws-durable-execution-sdk-python-testing/src/aws_durable_execution_sdk_python_testing/runner.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,17 @@ def _wait_for_completion(
10541054
DurableExecutionArn=execution_arn
10551055
)
10561056
execution = GetDurableExecutionResponse.from_dict(execution_dict)
1057+
except ClientError as e:
1058+
error_code = e.response.get("Error", {}).get("Code")
1059+
# Retry while the asynchronous invoke's durable execution record is
1060+
# still becoming visible to GetDurableExecution.
1061+
if error_code == "ResourceNotFoundException":
1062+
logger.info("Execution status not available yet; retrying")
1063+
time.sleep(self.poll_interval)
1064+
continue
1065+
1066+
msg = f"Failed to get execution status: {e}"
1067+
raise DurableFunctionsTestError(msg) from e
10571068
except Exception as e:
10581069
msg = f"Failed to get execution status: {e}"
10591070
raise DurableFunctionsTestError(msg) from e

packages/aws-durable-execution-sdk-python-testing/tests/runner_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,43 @@ def test_cloud_runner_run_missing_execution_arn(mock_boto3):
13861386
runner.run(input="test-input")
13871387

13881388

1389+
@patch("aws_durable_execution_sdk_python_testing.runner.boto3")
1390+
def test_cloud_runner_wait_for_completion_get_execution_resource_not_found_retries(
1391+
mock_boto3,
1392+
):
1393+
"""Test _wait_for_completion retries transient ResourceNotFoundException."""
1394+
from botocore.exceptions import ClientError # type: ignore
1395+
1396+
from aws_durable_execution_sdk_python_testing.runner import (
1397+
DurableFunctionCloudTestRunner,
1398+
)
1399+
1400+
mock_client = Mock()
1401+
mock_boto3.client.return_value = mock_client
1402+
mock_client.get_durable_execution.side_effect = [
1403+
ClientError(
1404+
error_response={"Error": {"Code": "ResourceNotFoundException"}},
1405+
operation_name="GetDurableExecution",
1406+
),
1407+
{
1408+
"DurableExecutionArn": "arn:aws:lambda:us-east-1:123456789012:function:test:execution:exec-1",
1409+
"DurableExecutionName": "test-execution",
1410+
"FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:test",
1411+
"Status": "SUCCEEDED",
1412+
"StartTimestamp": "2023-01-01T00:00:00Z",
1413+
"EndTimestamp": "2023-01-01T00:01:00Z",
1414+
},
1415+
]
1416+
1417+
runner = DurableFunctionCloudTestRunner(
1418+
function_name="test-function", poll_interval=0
1419+
)
1420+
result = runner._wait_for_completion("test-arn", timeout=10)
1421+
1422+
assert result.status == "SUCCEEDED"
1423+
assert mock_client.get_durable_execution.call_count == 2
1424+
1425+
13891426
@patch("aws_durable_execution_sdk_python_testing.runner.boto3")
13901427
def test_cloud_runner_wait_for_completion_get_execution_failure(mock_boto3):
13911428
"""Test DurableFunctionCloudTestRunner._wait_for_completion with API failure."""

0 commit comments

Comments
 (0)