|
11 | 11 | ) |
12 | 12 | from aws_durable_execution_sdk_python.exceptions import ( |
13 | 13 | CallableRuntimeError, |
| 14 | + FatalError, |
14 | 15 | SuspendExecution, |
15 | 16 | ) |
16 | 17 | from aws_durable_execution_sdk_python.identifier import OperationIdentifier |
@@ -372,6 +373,7 @@ def test_wait_for_condition_no_operation_in_checkpoint(): |
372 | 373 | mock_result = Mock() |
373 | 374 | mock_result.is_succeeded.return_value = False |
374 | 375 | mock_result.is_failed.return_value = False |
| 376 | + mock_result.is_pending.return_value = False |
375 | 377 | mock_result.is_started_or_ready.return_value = True |
376 | 378 | mock_result.is_existent.return_value = True |
377 | 379 | mock_result.result = json.dumps(10) |
@@ -416,6 +418,7 @@ def test_wait_for_condition_operation_no_step_details(): |
416 | 418 | mock_result = Mock() |
417 | 419 | mock_result.is_succeeded.return_value = False |
418 | 420 | mock_result.is_failed.return_value = False |
| 421 | + mock_result.is_pending.return_value = False |
419 | 422 | mock_result.is_started_or_ready.return_value = True |
420 | 423 | mock_result.is_existent.return_value = True |
421 | 424 | mock_result.result = json.dumps(10) |
@@ -651,3 +654,72 @@ def check_func(state, context): |
651 | 654 | ) |
652 | 655 |
|
653 | 656 | assert result == {"key": "value", "number": 42, "list": [1, 2, 3]} |
| 657 | + |
| 658 | + |
| 659 | +def test_wait_for_condition_pending(): |
| 660 | + mock_state = Mock(spec=ExecutionState) |
| 661 | + mock_state.durable_execution_arn = "arn:aws:test" |
| 662 | + operation = Operation( |
| 663 | + operation_id="XXX", |
| 664 | + operation_type=OperationType.STEP, |
| 665 | + status=OperationStatus.PENDING, |
| 666 | + step_details=StepDetails( |
| 667 | + result='{"key": "VALUE", "number": "84", "list": [1, 2, 3]}', |
| 668 | + next_attempt_timestamp="1764547200", |
| 669 | + ), |
| 670 | + ) |
| 671 | + mock_result = CheckpointedResult.create_from_operation(operation) |
| 672 | + mock_state.get_checkpoint_result.return_value = mock_result |
| 673 | + |
| 674 | + mock_logger = Mock(spec=Logger) |
| 675 | + mock_logger.with_log_info.return_value = mock_logger |
| 676 | + |
| 677 | + op_id = OperationIdentifier("op1", None, "test_wait") |
| 678 | + |
| 679 | + def check_func(state, context): |
| 680 | + msg = "Should not be called" |
| 681 | + raise FatalError(msg) |
| 682 | + |
| 683 | + config = WaitForConditionConfig( |
| 684 | + initial_state=5, |
| 685 | + wait_strategy=lambda s, a: WaitForConditionDecision.stop_polling(), |
| 686 | + serdes=CustomDictSerDes(), |
| 687 | + ) |
| 688 | + |
| 689 | + with pytest.raises( |
| 690 | + SuspendExecution, match="wait_for_condition test_wait will retry at timestamp" |
| 691 | + ): |
| 692 | + wait_for_condition_handler(check_func, config, mock_state, op_id, mock_logger) |
| 693 | + |
| 694 | + |
| 695 | +def test_wait_for_condition_pending_without_next_attempt(): |
| 696 | + mock_state = Mock(spec=ExecutionState) |
| 697 | + mock_state.durable_execution_arn = "arn:aws:test" |
| 698 | + operation = Operation( |
| 699 | + operation_id="XXX", |
| 700 | + operation_type=OperationType.STEP, |
| 701 | + status=OperationStatus.PENDING, |
| 702 | + step_details=StepDetails( |
| 703 | + result='{"key": "VALUE", "number": "84", "list": [1, 2, 3]}', |
| 704 | + ), |
| 705 | + ) |
| 706 | + mock_result = CheckpointedResult.create_from_operation(operation) |
| 707 | + mock_state.get_checkpoint_result.return_value = mock_result |
| 708 | + |
| 709 | + mock_logger = Mock(spec=Logger) |
| 710 | + mock_logger.with_log_info.return_value = mock_logger |
| 711 | + |
| 712 | + op_id = OperationIdentifier("op1", None, "test_wait") |
| 713 | + |
| 714 | + def check_func(state, context): |
| 715 | + msg = "Should not be called" |
| 716 | + raise FatalError(msg) |
| 717 | + |
| 718 | + config = WaitForConditionConfig( |
| 719 | + initial_state=5, |
| 720 | + wait_strategy=lambda s, a: WaitForConditionDecision.stop_polling(), |
| 721 | + serdes=CustomDictSerDes(), |
| 722 | + ) |
| 723 | + |
| 724 | + with pytest.raises(SuspendExecution, match="next_attempt_timestamp is None"): |
| 725 | + wait_for_condition_handler(check_func, config, mock_state, op_id, mock_logger) |
0 commit comments