Skip to content

Commit 5ab91f2

Browse files
committed
chore: fix mocks for start input to have execution timeout
1 parent 6921dd6 commit 5ab91f2

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/aws_durable_execution_sdk_python_testing/executor.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,19 @@ def start_execution(
120120
self._completion_events[execution.durable_execution_arn] = completion_event
121121

122122
# Schedule execution timeout
123-
try:
124-
timeout_seconds = input.execution_timeout_seconds
125-
if timeout_seconds and timeout_seconds > 0:
126-
127-
def timeout_handler():
128-
error = ErrorObject.from_message(
129-
f"Execution timed out after {timeout_seconds} seconds."
130-
)
131-
self.on_timed_out(execution.durable_execution_arn, error)
123+
if input.execution_timeout_seconds > 0:
132124

133-
self._execution_timeout = self._scheduler.call_later(
134-
timeout_handler,
135-
delay=timeout_seconds,
136-
completion_event=completion_event,
125+
def timeout_handler():
126+
error = ErrorObject.from_message(
127+
f"Execution timed out after {input.execution_timeout_seconds} seconds."
137128
)
138-
except (AttributeError, TypeError):
139-
# Handle Mock objects or invalid timeout values in tests
140-
pass
129+
self.on_timed_out(execution.durable_execution_arn, error)
130+
131+
self._execution_timeout = self._scheduler.call_later(
132+
timeout_handler,
133+
delay=input.execution_timeout_seconds,
134+
completion_event=completion_event,
135+
)
141136

142137
# Schedule initial invocation to run immediately
143138
self._invoke_execution(execution.durable_execution_arn)

tests/executor_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ def test_wait_until_complete_success(executor, mock_scheduler):
12131213
mock_execution_class.new.return_value = mock_execution
12141214

12151215
start_input = Mock()
1216+
start_input.execution_timeout_seconds = 0
12161217
executor.start_execution(start_input)
12171218

12181219
result = executor.wait_until_complete("test-arn", timeout=10)
@@ -1236,6 +1237,7 @@ def test_wait_until_complete_timeout(executor, mock_scheduler):
12361237
mock_execution_class.new.return_value = mock_execution
12371238

12381239
start_input = Mock()
1240+
start_input.execution_timeout_seconds = 0
12391241
executor.start_execution(start_input)
12401242

12411243
result = executor.wait_until_complete("test-arn", timeout=10)
@@ -1290,6 +1292,7 @@ def test_should_schedule_wait_timer_correctly(executor, mock_scheduler):
12901292
mock_execution_class.new.return_value = mock_execution
12911293

12921294
start_input = Mock()
1295+
start_input.execution_timeout_seconds = 0
12931296
executor.start_execution(start_input)
12941297

12951298
# Act - schedule wait timer through public method
@@ -1444,6 +1447,7 @@ def test_on_wait_timer_scheduled(executor, mock_scheduler):
14441447
mock_execution_class.new.return_value = mock_execution
14451448

14461449
start_input = Mock()
1450+
start_input.execution_timeout_seconds = 0
14471451
executor.start_execution(start_input)
14481452

14491453
with patch.object(executor, "_on_wait_succeeded"):
@@ -1654,6 +1658,7 @@ def test_invoke_execution_with_delay_through_wait_timer(executor, mock_scheduler
16541658
mock_execution_class.new.return_value = mock_execution
16551659

16561660
start_input = Mock()
1661+
start_input.execution_timeout_seconds = 0
16571662
executor.start_execution(start_input)
16581663

16591664
# Test delay behavior through wait timer scheduling
@@ -1681,6 +1686,7 @@ def test_invoke_execution_no_delay_through_start_execution(executor, mock_schedu
16811686
mock_execution_class.new.return_value = mock_execution
16821687

16831688
start_input = Mock()
1689+
start_input.execution_timeout_seconds = 0
16841690
executor.start_execution(start_input)
16851691

16861692
# Verify scheduler was called with no delay for initial execution
@@ -1704,6 +1710,7 @@ def test_on_step_retry_scheduled(executor, mock_scheduler):
17041710
mock_execution_class.new.return_value = mock_execution
17051711

17061712
start_input = Mock()
1713+
start_input.execution_timeout_seconds = 0
17071714
executor.start_execution(start_input)
17081715

17091716
with patch.object(executor, "_on_retry_ready"):
@@ -1733,6 +1740,7 @@ def test_wait_handler_execution(executor, mock_scheduler):
17331740
mock_execution_class.new.return_value = mock_execution
17341741

17351742
start_input = Mock()
1743+
start_input.execution_timeout_seconds = 0
17361744
executor.start_execution(start_input)
17371745

17381746
with patch.object(executor, "_on_wait_succeeded") as mock_wait:
@@ -1764,6 +1772,7 @@ def test_retry_handler_execution(executor, mock_scheduler):
17641772
mock_execution_class.new.return_value = mock_execution
17651773

17661774
start_input = Mock()
1775+
start_input.execution_timeout_seconds = 0
17671776
executor.start_execution(start_input)
17681777

17691778
with patch.object(executor, "_on_retry_ready") as mock_retry:

0 commit comments

Comments
 (0)