|
3 | 3 | import pytest |
4 | 4 | from aws_durable_execution_sdk_python.execution import InvocationStatus |
5 | 5 | from aws_durable_execution_sdk_python.lambda_service import OperationType |
6 | | - |
7 | 6 | from src.step import steps_with_retry |
8 | 7 | from test.conftest import deserialize_operation_payload |
9 | 8 |
|
|
14 | 13 | lambda_function_name="steps with retry", |
15 | 14 | ) |
16 | 15 | def test_steps_with_retry(durable_runner): |
17 | | - """Test steps_with_retry pattern.""" |
| 16 | + """Test steps_with_retry pattern. |
| 17 | +
|
| 18 | + With counter-based deterministic behavior: |
| 19 | + - Poll 1, Attempt 1: counter = 1 → raises RuntimeError ❌ |
| 20 | + - Poll 1, Attempt 2: counter = 2 → returns None |
| 21 | + - Poll 2, Attempt 1: counter = 3 → returns item ✓ |
| 22 | +
|
| 23 | + The function finds the item on poll 2 after 1 retry on poll 1. |
| 24 | + """ |
18 | 25 | with durable_runner: |
19 | 26 | result = durable_runner.run(input={"name": "test-item"}, timeout=30) |
20 | 27 |
|
21 | 28 | assert result.status is InvocationStatus.SUCCEEDED |
22 | 29 |
|
23 | | - # Result should be either success with item or error |
24 | | - assert isinstance(deserialize_operation_payload(result.result), dict) |
25 | | - assert "success" in deserialize_operation_payload( |
26 | | - result.result |
27 | | - ) or "error" in deserialize_operation_payload(result.result) |
| 30 | + # With counter-based deterministic behavior, finds item on poll 2 |
| 31 | + result_data = deserialize_operation_payload(result.result) |
| 32 | + assert isinstance(result_data, dict) |
| 33 | + assert result_data.get("success") is True |
| 34 | + assert result_data.get("pollsRequired") == 2 |
| 35 | + assert "item" in result_data |
| 36 | + assert result_data["item"]["id"] == "test-item" |
28 | 37 |
|
29 | | - # Verify step operations exist (polling steps) |
| 38 | + # Verify step operations exist |
30 | 39 | step_ops = [ |
31 | 40 | op for op in result.operations if op.operation_type == OperationType.STEP |
32 | 41 | ] |
33 | | - assert len(step_ops) >= 1 |
| 42 | + # Should have exactly 2 step operations (poll 1 and poll 2) |
| 43 | + assert len(step_ops) == 2 |
| 44 | + |
| 45 | + # Poll 1: succeeded after 1 retry (returned None) |
| 46 | + assert step_ops[0].name == "get_item_poll_1" |
| 47 | + assert step_ops[0].result == "null" |
| 48 | + assert step_ops[0].attempt == 2 # 1 retry occurred (1-indexed: 2=first retry) |
| 49 | + |
| 50 | + # Poll 2: succeeded immediately (returned item) |
| 51 | + assert step_ops[1].name == "get_item_poll_2" |
| 52 | + assert step_ops[1].attempt == 1 # No retries needed (1-indexed: 1=initial) |
0 commit comments