diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index 10ff48db..0f619dca 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -154,8 +154,8 @@ class WorkflowExecution(object): # workflow execution timeout _timeout = self.first_timeout() if _timeout: - self.execute_timeout(_timeout) - # TODO: process child policy on child workflows here or in process_timeouts() + self.timeout(_timeout) + # TODO: process child policy on child workflows here or in timeout() self._add_event( "WorkflowExecutionTimedOut", child_policy=self.child_policy, @@ -168,7 +168,7 @@ class WorkflowExecution(object): _timeout = task.first_timeout() if task.state == "STARTED" and _timeout: self.should_schedule_decision_next = True - task.process_timeouts() + task.timeout(_timeout) self._add_event( "DecisionTaskTimedOut", event_timestamp=_timeout.timestamp, @@ -182,7 +182,7 @@ class WorkflowExecution(object): _timeout = task.first_timeout() if task.open and _timeout: self.should_schedule_decision_next = True - task.process_timeouts() + task.timeout(_timeout) self._add_event( "ActivityTaskTimedOut", details=task.details, @@ -538,16 +538,11 @@ class WorkflowExecution(object): if _timeout.reached: return _timeout - def execute_timeout(self, timeout): + def timeout(self, timeout): self.execution_status = "CLOSED" self.close_status = "TIMED_OUT" self.timeout_type = timeout.kind - def process_timeouts(self): - _timeout = self.first_timeout() - if _timeout: - self.execute_timeout(_timeout) - @property def open(self): return self.execution_status == "OPEN" diff --git a/tests/test_swf/models/test_activity_task.py b/tests/test_swf/models/test_activity_task.py index ef4823cc..4dbb3cc1 100644 --- a/tests/test_swf/models/test_activity_task.py +++ b/tests/test_swf/models/test_activity_task.py @@ -8,7 +8,11 @@ from moto.swf.models import ( Timeout, ) -from ..utils import make_workflow_execution, ACTIVITY_TASK_TIMEOUTS +from ..utils import ( + ACTIVITY_TASK_TIMEOUTS, + make_workflow_execution, + process_first_timeout, +) def test_activity_task_creation(): @@ -101,7 +105,7 @@ def test_activity_task_first_timeout(): # activity task timeout is 300s == 5mins with freeze_time("2015-01-01 12:06:00"): task.first_timeout().should.be.a(Timeout) - task.process_timeouts() + process_first_timeout(task) task.state.should.equal("TIMED_OUT") task.timeout_type.should.equal("HEARTBEAT") @@ -123,7 +127,7 @@ def test_activity_task_cannot_timeout_on_closed_workflow_execution(): with freeze_time("2015-01-01 14:10:00"): task.first_timeout().should.be.a(Timeout) wfe.first_timeout().should.be.a(Timeout) - wfe.process_timeouts() + process_first_timeout(wfe) task.first_timeout().should.be.none def test_activity_task_cannot_change_state_on_closed_workflow_execution(): diff --git a/tests/test_swf/models/test_decision_task.py b/tests/test_swf/models/test_decision_task.py index f85b83eb..2c4439dd 100644 --- a/tests/test_swf/models/test_decision_task.py +++ b/tests/test_swf/models/test_decision_task.py @@ -4,7 +4,7 @@ from sure import expect from moto.swf.exceptions import SWFWorkflowExecutionClosedError from moto.swf.models import DecisionTask, Timeout -from ..utils import make_workflow_execution +from ..utils import make_workflow_execution, process_first_timeout def test_decision_task_creation(): @@ -60,7 +60,7 @@ def test_decision_task_cannot_timeout_on_closed_workflow_execution(): with freeze_time("2015-01-01 14:10:00"): dt.first_timeout().should.be.a(Timeout) wfe.first_timeout().should.be.a(Timeout) - wfe.process_timeouts() + process_first_timeout(wfe) dt.first_timeout().should.be.none def test_decision_task_cannot_change_state_on_closed_workflow_execution(): diff --git a/tests/test_swf/utils.py b/tests/test_swf/utils.py index 7e7ecc1f..d98294ea 100644 --- a/tests/test_swf/utils.py +++ b/tests/test_swf/utils.py @@ -82,3 +82,10 @@ def setup_workflow(): wfe = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0") conn.run_id = wfe["runId"] return conn + + +# A helper for processing the first timeout on a given object +def process_first_timeout(obj): + _timeout = obj.first_timeout() + if _timeout: + obj.timeout(_timeout)