11"""Unit tests for executor module."""
22
33import asyncio
4+ import uuid
45from datetime import UTC , datetime
56from unittest .mock import Mock , patch
67
@@ -142,7 +143,26 @@ def test_start_execution(
142143 result = executor .start_execution (start_input )
143144
144145 # Test observable behavior through public API
145- mock_execution_class .new .assert_called_once_with (input = start_input )
146+ # The executor should generate an invocation_id if not provided
147+ call_args = mock_execution_class .new .call_args
148+ actual_input = call_args .kwargs ["input" ]
149+
150+ # Verify all fields match except invocation_id should be generated
151+ assert actual_input .account_id == start_input .account_id
152+ assert actual_input .function_name == start_input .function_name
153+ assert actual_input .function_qualifier == start_input .function_qualifier
154+ assert actual_input .execution_name == start_input .execution_name
155+ assert (
156+ actual_input .execution_timeout_seconds == start_input .execution_timeout_seconds
157+ )
158+ assert (
159+ actual_input .execution_retention_period_days
160+ == start_input .execution_retention_period_days
161+ )
162+ assert actual_input .invocation_id is not None # Should be generated
163+ assert actual_input .trace_fields == start_input .trace_fields
164+ assert actual_input .tenant_id == start_input .tenant_id
165+ assert actual_input .input == start_input .input
146166 mock_execution .start .assert_called_once ()
147167 mock_store .save .assert_called_once_with (mock_execution )
148168 mock_scheduler .create_event .assert_called_once ()
@@ -157,7 +177,39 @@ def test_start_execution(
157177 mock_event .wait .assert_called_once_with (1 )
158178
159179
160- def test_get_execution (executor , mock_store ):
180+ @patch ("aws_durable_execution_sdk_python_testing.executor.Execution" )
181+ def test_start_execution_with_provided_invocation_id (
182+ mock_execution_class , executor , mock_store , mock_scheduler
183+ ):
184+ # Create input with invocation_id already provided
185+ provided_invocation_id = "user-provided-id-123"
186+ start_input = StartDurableExecutionInput (
187+ account_id = "123456789012" ,
188+ function_name = "test-function" ,
189+ function_qualifier = "$LATEST" ,
190+ execution_name = "test-execution" ,
191+ execution_timeout_seconds = 300 ,
192+ execution_retention_period_days = 7 ,
193+ invocation_id = provided_invocation_id ,
194+ )
195+
196+ mock_execution = Mock ()
197+ mock_execution .durable_execution_arn = "test-arn"
198+ mock_execution_class .new .return_value = mock_execution
199+ mock_event = Mock ()
200+ mock_scheduler .create_event .return_value = mock_event
201+
202+ with patch .object (executor , "_invoke_execution" ) as mock_invoke :
203+ result = executor .start_execution (start_input )
204+
205+ # Should use the provided invocation_id unchanged
206+ mock_execution_class .new .assert_called_once_with (input = start_input )
207+ mock_execution .start .assert_called_once ()
208+ mock_store .save .assert_called_once_with (mock_execution )
209+ mock_scheduler .create_event .assert_called_once ()
210+ mock_invoke .assert_called_once_with ("test-arn" )
211+ assert result .execution_arn == "test-arn"
212+
161213 mock_execution = Mock ()
162214 mock_store .load .return_value = mock_execution
163215
0 commit comments