|
14 | 14 | lambda_function_name="steps with retry", |
15 | 15 | ) |
16 | 16 | def test_steps_with_retry(durable_runner): |
17 | | - """Test steps_with_retry pattern.""" |
| 17 | + """Test steps_with_retry pattern. |
| 18 | +
|
| 19 | + With seed 42 set by conftest fixture, the random state persists: |
| 20 | + - Poll 1, Attempt 0: random() = 0.639 ≥ 0.5 (passes), random() = 0.025 ≤ 0.3 → returns None |
| 21 | + - Poll 2, Attempt 0: random() = 0.275 < 0.5 → raises RuntimeError ❌ |
| 22 | + - Poll 2, Attempt 1: random() = 0.736 ≥ 0.5 (passes), random() = 0.676 > 0.3 → returns item ✓ |
| 23 | +
|
| 24 | + The function finds the item on poll 2 after 1 retry. |
| 25 | + """ |
18 | 26 | with durable_runner: |
19 | 27 | result = durable_runner.run(input={"name": "test-item"}, timeout=30) |
20 | 28 |
|
21 | 29 | assert result.status is InvocationStatus.SUCCEEDED |
22 | 30 |
|
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) |
| 31 | + # With seeded random (seed=42) at module level, finds item on poll 2 |
| 32 | + result_data = deserialize_operation_payload(result.result) |
| 33 | + assert isinstance(result_data, dict) |
| 34 | + assert result_data.get("success") is True |
| 35 | + assert result_data.get("pollsRequired") == 2 |
| 36 | + assert "item" in result_data |
| 37 | + assert result_data["item"]["id"] == "test-item" |
28 | 38 |
|
29 | | - # Verify step operations exist (polling steps) |
| 39 | + # Verify step operations exist |
30 | 40 | step_ops = [ |
31 | 41 | op for op in result.operations if op.operation_type == OperationType.STEP |
32 | 42 | ] |
33 | | - assert len(step_ops) >= 1 |
| 43 | + # Should have exactly 2 step operations (poll 1 and poll 2) |
| 44 | + assert len(step_ops) == 2 |
| 45 | + |
| 46 | + # Poll 1: succeeded immediately (returned None) |
| 47 | + assert step_ops[0].name == "get_item_poll_1" |
| 48 | + assert step_ops[0].result == "null" |
| 49 | + assert step_ops[0].attempt == 1 # No retries needed (1-indexed: 1=initial) |
| 50 | + |
| 51 | + # Poll 2: succeeded after 1 retry (returned item) |
| 52 | + assert step_ops[1].name == "get_item_poll_2" |
| 53 | + assert ( |
| 54 | + step_ops[1].attempt == 2 |
| 55 | + ) # Exactly 1 retry occurred (1-indexed: 2=first retry) |
0 commit comments