From 49e44c8ee653a7e1260dd5c407c9733cf25b00e9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Sat, 24 Oct 2015 12:05:42 +0200 Subject: [PATCH] Fix openDecisionTasks counter not updated when we complete a DecisionTask --- moto/swf/models/workflow_execution.py | 9 ++++++--- tests/test_swf/test_decision_tasks.py | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/moto/swf/models/workflow_execution.py b/moto/swf/models/workflow_execution.py index c22d3e021..3d2031c7e 100644 --- a/moto/swf/models/workflow_execution.py +++ b/moto/swf/models/workflow_execution.py @@ -279,10 +279,10 @@ class WorkflowExecution(object): Handles a Decision according to SWF docs. See: http://docs.aws.amazon.com/amazonswf/latest/apireference/API_Decision.html """ - # 'decisions' can be None per boto.swf defaults, so better exiting - # directly for falsy values + # 'decisions' can be None per boto.swf defaults, so replace it with something iterable if not decisions: - return + decisions = [] + # handle each decision separately, in order for decision in decisions: decision_type = decision["decisionType"] @@ -306,6 +306,9 @@ class WorkflowExecution(object): # TODO: implement Decision type: StartTimer raise NotImplementedError("Cannot handle decision: {}".format(decision_type)) + # finally decrement counter if and only if everything went well + self.open_counts["openDecisionTasks"] -= 1 + def complete(self, event_id, result=None): self.execution_status = "CLOSED" self.close_status = "COMPLETED" diff --git a/tests/test_swf/test_decision_tasks.py b/tests/test_swf/test_decision_tasks.py index a07eecbfb..568d68c2d 100644 --- a/tests/test_swf/test_decision_tasks.py +++ b/tests/test_swf/test_decision_tasks.py @@ -76,6 +76,15 @@ def test_count_pending_decision_tasks_on_non_existent_task_list(): resp = conn.count_pending_decision_tasks("test-domain", "non-existent") resp.should.equal({"count": 0, "truncated": False}) +@mock_swf +def test_count_pending_decision_tasks_after_decision_completes(): + conn = setup_workflow() + resp = conn.poll_for_decision_task("test-domain", "queue") + conn.respond_decision_task_completed(resp["taskToken"]) + + resp = conn.count_pending_decision_tasks("test-domain", "queue") + resp.should.equal({"count": 0, "truncated": False}) + # RespondDecisionTaskCompleted endpoint @mock_swf