From 65c35bfa691cec8a59ad196269692d50b155a709 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Thu, 5 Nov 2015 02:40:16 +0100 Subject: [PATCH] Make timeout events appear at the right time in workflow history --- moto/swf/models/workflow_execution.py | 10 ++++++++-- tests/test_swf/responses/test_timeouts.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index 2c1e74a02..10ff48db1 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -159,16 +159,19 @@ class WorkflowExecution(object): self._add_event( "WorkflowExecutionTimedOut", child_policy=self.child_policy, + event_timestamp=_timeout.timestamp, timeout_type=self.timeout_type, ) # decision tasks timeouts for task in self.decision_tasks: - if task.state == "STARTED" and task.first_timeout(): + _timeout = task.first_timeout() + if task.state == "STARTED" and _timeout: self.should_schedule_decision_next = True task.process_timeouts() self._add_event( "DecisionTaskTimedOut", + event_timestamp=_timeout.timestamp, scheduled_event_id=task.scheduled_event_id, started_event_id=task.started_event_id, timeout_type=task.timeout_type, @@ -176,17 +179,20 @@ class WorkflowExecution(object): # activity tasks timeouts for task in self.activity_tasks: - if task.open and task.first_timeout(): + _timeout = task.first_timeout() + if task.open and _timeout: self.should_schedule_decision_next = True task.process_timeouts() self._add_event( "ActivityTaskTimedOut", details=task.details, + event_timestamp=_timeout.timestamp, scheduled_event_id=task.scheduled_event_id, started_event_id=task.started_event_id, timeout_type=task.timeout_type, ) # schedule decision task if needed + # TODO: make decision appear as if it has been scheduled immediately after the timeout if self.should_schedule_decision_next: self.schedule_decision_task() diff --git a/tests/test_swf/responses/test_timeouts.py b/tests/test_swf/responses/test_timeouts.py index ecc1e6068..237deaea8 100644 --- a/tests/test_swf/responses/test_timeouts.py +++ b/tests/test_swf/responses/test_timeouts.py @@ -30,6 +30,8 @@ def test_activity_task_heartbeat_timeout(): resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut") attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"] attrs["timeoutType"].should.equal("HEARTBEAT") + # checks that event has been emitted at 12:05:00, not 12:05:30 + resp["events"][-2]["eventTimestamp"].should.equal(1420113900) resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled") @@ -63,6 +65,8 @@ def test_decision_task_start_to_close_timeout(): attrs.should.equal({ "scheduledEventId": 2, "startedEventId": 3, "timeoutType": "START_TO_CLOSE" }) + # checks that event has been emitted at 12:05:00, not 12:05:30 + resp["events"][-2]["eventTimestamp"].should.equal(1420113900) # Workflow Execution Start to Close timeout # Default value in workflow helpers: 2 hours @@ -92,3 +96,5 @@ def test_workflow_execution_start_to_close_timeout(): attrs.should.equal({ "childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE" }) + # checks that event has been emitted at 14:00:00, not 14:00:30 + resp["events"][-1]["eventTimestamp"].should.equal(1420120800)