|
| 1 | +"""Tests for create_callback_failures.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from aws_durable_execution_sdk_python.execution import InvocationStatus |
| 5 | +from aws_durable_execution_sdk_python.lambda_service import ErrorObject |
| 6 | + |
| 7 | +from src.callback import callback_failure |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.example |
| 11 | +@pytest.mark.durable_execution( |
| 12 | + handler=callback_failure.handler, |
| 13 | + lambda_function_name="Create Callback Failures Uncaught", |
| 14 | +) |
| 15 | +def test_handle_callback_operations_with_failure_uncaught(durable_runner): |
| 16 | + """Test handling callback operations with failure.""" |
| 17 | + test_payload = {"shouldCatchError": False} |
| 18 | + |
| 19 | + with durable_runner: |
| 20 | + execution_arn = durable_runner.run_async(input=test_payload, timeout=30) |
| 21 | + |
| 22 | + callback_id = durable_runner.wait_for_callback(execution_arn=execution_arn) |
| 23 | + |
| 24 | + durable_runner.send_callback_failure( |
| 25 | + callback_id=callback_id, |
| 26 | + error=ErrorObject.from_message("External API failure"), |
| 27 | + ) |
| 28 | + |
| 29 | + result = durable_runner.wait_for_result(execution_arn=execution_arn) |
| 30 | + |
| 31 | + assert result.status is InvocationStatus.FAILED |
| 32 | + |
| 33 | + error = result.error |
| 34 | + assert error is not None |
| 35 | + assert "External API failure" in error.message |
| 36 | + assert error.type == "CallbackError" |
| 37 | + assert error.stack_trace is None |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.example |
| 41 | +@pytest.mark.durable_execution( |
| 42 | + handler=callback_failure.handler, |
| 43 | + lambda_function_name="Create Callback Failures Caught Error", |
| 44 | +) |
| 45 | +def test_handle_callback_operations_with_caught_error(durable_runner): |
| 46 | + """Test handling callback operations with caught error.""" |
| 47 | + test_payload = {"shouldCatchError": True} |
| 48 | + |
| 49 | + with durable_runner: |
| 50 | + execution_arn = durable_runner.run_async(input=test_payload, timeout=30) |
| 51 | + callback_id = durable_runner.wait_for_callback(execution_arn=execution_arn) |
| 52 | + durable_runner.send_callback_failure( |
| 53 | + callback_id=callback_id, |
| 54 | + error=ErrorObject.from_message("External API failure"), |
| 55 | + ) |
| 56 | + result = durable_runner.wait_for_result(execution_arn=execution_arn) |
| 57 | + |
| 58 | + assert result.status is InvocationStatus.SUCCEEDED |
| 59 | + |
| 60 | + from test.conftest import deserialize_operation_payload |
| 61 | + |
| 62 | + result_data = deserialize_operation_payload(result.result) |
| 63 | + assert result_data["success"] is False |
| 64 | + assert "External API failure" in result_data["error"] |
0 commit comments