diff --git a/moto/swf/models/activity_task.py b/moto/swf/models/activity_task.py index 93e300ae5..5c160acc4 100644 --- a/moto/swf/models/activity_task.py +++ b/moto/swf/models/activity_task.py @@ -73,7 +73,10 @@ class ActivityTask(BaseModel): def first_timeout(self): if not self.open or not self.workflow_execution.open: return None - # TODO: handle the "NONE" case + + if self.timeouts["heartbeatTimeout"] == "NONE": + return None + heartbeat_timeout_at = self.last_heartbeat_timestamp + int( self.timeouts["heartbeatTimeout"] ) diff --git a/moto/swf/responses.py b/moto/swf/responses.py index 17ec7281a..a2d576a11 100644 --- a/moto/swf/responses.py +++ b/moto/swf/responses.py @@ -446,9 +446,7 @@ class SWFResponse(BaseResponse): if decision: return json.dumps(decision.to_full_dict(reverse_order=reverse_order)) else: - return json.dumps( - {"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""} - ) + return json.dumps({"previousStartedEventId": 0, "startedEventId": 0}) def count_pending_decision_tasks(self): domain_name = self._params["domain"] @@ -482,7 +480,7 @@ class SWFResponse(BaseResponse): if activity_task: return json.dumps(activity_task.to_full_dict()) else: - return json.dumps({"startedEventId": 0, "taskToken": ""}) + return json.dumps({"startedEventId": 0}) def count_pending_activity_tasks(self): domain_name = self._params["domain"] diff --git a/tests/test_swf/models/test_activity_task.py b/tests/test_swf/models/test_activity_task.py index 96f7c345f..bedbaade0 100644 --- a/tests/test_swf/models/test_activity_task.py +++ b/tests/test_swf/models/test_activity_task.py @@ -108,6 +108,24 @@ def test_activity_task_first_timeout(): task.timeout_type.should.equal("HEARTBEAT") +def test_activity_task_first_timeout_with_heartbeat_timeout_none(): + wfe = make_workflow_execution() + + activity_task_timeouts = ACTIVITY_TASK_TIMEOUTS.copy() + activity_task_timeouts["heartbeatTimeout"] = "NONE" + + with freeze_time("2015-01-01 12:00:00"): + task = ActivityTask( + activity_id="my-activity-123", + activity_type="foo", + input="optional", + scheduled_event_id=117, + timeouts=activity_task_timeouts, + workflow_execution=wfe, + ) + task.first_timeout().should.be.none + + def test_activity_task_cannot_timeout_on_closed_workflow_execution(): with freeze_time("2015-01-01 12:00:00"): wfe = make_workflow_execution() diff --git a/tests/test_swf/responses/test_activity_tasks.py b/tests/test_swf/responses/test_activity_tasks.py index 4fa965b11..0b72b7ca7 100644 --- a/tests/test_swf/responses/test_activity_tasks.py +++ b/tests/test_swf/responses/test_activity_tasks.py @@ -35,14 +35,14 @@ def test_poll_for_activity_task_when_one(): def test_poll_for_activity_task_when_none(): conn = setup_workflow() resp = conn.poll_for_activity_task("test-domain", "activity-task-list") - resp.should.equal({"startedEventId": 0, "taskToken": ""}) + resp.should.equal({"startedEventId": 0}) @mock_swf_deprecated def test_poll_for_activity_task_on_non_existent_queue(): conn = setup_workflow() resp = conn.poll_for_activity_task("test-domain", "non-existent-queue") - resp.should.equal({"startedEventId": 0, "taskToken": ""}) + resp.should.equal({"startedEventId": 0}) # CountPendingActivityTasks endpoint diff --git a/tests/test_swf/responses/test_decision_tasks.py b/tests/test_swf/responses/test_decision_tasks.py index 3c55b58c8..6493302f9 100644 --- a/tests/test_swf/responses/test_decision_tasks.py +++ b/tests/test_swf/responses/test_decision_tasks.py @@ -62,18 +62,14 @@ def test_poll_for_decision_task_when_none(): resp = conn.poll_for_decision_task("test-domain", "queue") # this is the DecisionTask representation you get from the real SWF # after waiting 60s when there's no decision to be taken - resp.should.equal( - {"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""} - ) + resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0}) @mock_swf_deprecated def test_poll_for_decision_task_on_non_existent_queue(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "non-existent-queue") - resp.should.equal( - {"previousStartedEventId": 0, "startedEventId": 0, "taskToken": ""} - ) + resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0}) @mock_swf_deprecated