Merge pull request #534 from ianfdk/master

Add SWF's list_open_workflow_executions and list_closed_workflow_executions
This commit is contained in:
Steve Pulec 2016-02-14 16:50:53 -05:00
commit ccc1cb42dd
23 changed files with 524 additions and 167 deletions

View File

@ -103,6 +103,8 @@ It gets even better! Moto isn't just S3. Here's the status of the other AWS serv
|------------------------------------------------------------------------------|
| STS | @mock_sts | core endpoints done |
|------------------------------------------------------------------------------|
| SWF | @mock_sfw | basic endpoints done |
|------------------------------------------------------------------------------|
```
### Another Example

View File

@ -4,82 +4,82 @@
# and subsequent docs for each decision type.
DECISIONS_FIELDS = {
"cancelTimerDecisionAttributes": {
"timerId": { "type": "string", "required": True }
"timerId": {"type": "string", "required": True}
},
"cancelWorkflowExecutionDecisionAttributes": {
"details": { "type": "string", "required": False }
"details": {"type": "string", "required": False}
},
"completeWorkflowExecutionDecisionAttributes": {
"result": { "type": "string", "required": False }
"result": {"type": "string", "required": False}
},
"continueAsNewWorkflowExecutionDecisionAttributes": {
"childPolicy": { "type": "string", "required": False },
"executionStartToCloseTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"lambdaRole": { "type": "string", "required": False },
"tagList": { "type": "string", "array": True, "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False },
"taskStartToCloseTimeout": { "type": "string", "required": False },
"workflowTypeVersion": { "type": "string", "required": False }
"childPolicy": {"type": "string", "required": False},
"executionStartToCloseTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"lambdaRole": {"type": "string", "required": False},
"tagList": {"type": "string", "array": True, "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False},
"taskStartToCloseTimeout": {"type": "string", "required": False},
"workflowTypeVersion": {"type": "string", "required": False}
},
"failWorkflowExecutionDecisionAttributes": {
"details": { "type": "string", "required": False },
"reason": { "type": "string", "required": False }
"details": {"type": "string", "required": False},
"reason": {"type": "string", "required": False}
},
"recordMarkerDecisionAttributes": {
"details": { "type": "string", "required": False },
"markerName": { "type": "string", "required": True }
"details": {"type": "string", "required": False},
"markerName": {"type": "string", "required": True}
},
"requestCancelActivityTaskDecisionAttributes": {
"activityId": { "type": "string", "required": True }
"activityId": {"type": "string", "required": True}
},
"requestCancelExternalWorkflowExecutionDecisionAttributes": {
"control": { "type": "string", "required": False },
"runId": { "type": "string", "required": False },
"workflowId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"runId": {"type": "string", "required": False},
"workflowId": {"type": "string", "required": True}
},
"scheduleActivityTaskDecisionAttributes": {
"activityId": { "type": "string", "required": True },
"activityType": { "type": "ActivityType", "required": True },
"control": { "type": "string", "required": False },
"heartbeatTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"scheduleToCloseTimeout": { "type": "string", "required": False },
"scheduleToStartTimeout": { "type": "string", "required": False },
"startToCloseTimeout": { "type": "string", "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False }
"activityId": {"type": "string", "required": True},
"activityType": {"type": "ActivityType", "required": True},
"control": {"type": "string", "required": False},
"heartbeatTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"scheduleToCloseTimeout": {"type": "string", "required": False},
"scheduleToStartTimeout": {"type": "string", "required": False},
"startToCloseTimeout": {"type": "string", "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False}
},
"scheduleLambdaFunctionDecisionAttributes": {
"id": { "type": "string", "required": True },
"input": { "type": "string", "required": False },
"name": { "type": "string", "required": True },
"startToCloseTimeout": { "type": "string", "required": False }
"id": {"type": "string", "required": True},
"input": {"type": "string", "required": False},
"name": {"type": "string", "required": True},
"startToCloseTimeout": {"type": "string", "required": False}
},
"signalExternalWorkflowExecutionDecisionAttributes": {
"control": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"runId": { "type": "string", "required": False },
"signalName": { "type": "string", "required": True },
"workflowId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"runId": {"type": "string", "required": False},
"signalName": {"type": "string", "required": True},
"workflowId": {"type": "string", "required": True}
},
"startChildWorkflowExecutionDecisionAttributes": {
"childPolicy": { "type": "string", "required": False },
"control": { "type": "string", "required": False },
"executionStartToCloseTimeout": { "type": "string", "required": False },
"input": { "type": "string", "required": False },
"lambdaRole": { "type": "string", "required": False },
"tagList": { "type": "string", "array": True, "required": False },
"taskList": { "type": "TaskList", "required": False },
"taskPriority": { "type": "string", "required": False },
"taskStartToCloseTimeout": { "type": "string", "required": False },
"workflowId": { "type": "string", "required": True },
"workflowType": { "type": "WorkflowType", "required": True }
"childPolicy": {"type": "string", "required": False},
"control": {"type": "string", "required": False},
"executionStartToCloseTimeout": {"type": "string", "required": False},
"input": {"type": "string", "required": False},
"lambdaRole": {"type": "string", "required": False},
"tagList": {"type": "string", "array": True, "required": False},
"taskList": {"type": "TaskList", "required": False},
"taskPriority": {"type": "string", "required": False},
"taskStartToCloseTimeout": {"type": "string", "required": False},
"workflowId": {"type": "string", "required": True},
"workflowType": {"type": "WorkflowType", "required": True}
},
"startTimerDecisionAttributes": {
"control": { "type": "string", "required": False },
"startToFireTimeout": { "type": "string", "required": True },
"timerId": { "type": "string", "required": True }
"control": {"type": "string", "required": False},
"startToFireTimeout": {"type": "string", "required": True},
"timerId": {"type": "string", "required": True}
}
}

View File

@ -98,13 +98,13 @@ class SWFDecisionValidationException(SWFClientError):
for pb in problems:
if pb["type"] == "null_value":
messages.append(
"Value null at '%(where)s' failed to satisfy constraint: "\
"Value null at '%(where)s' failed to satisfy constraint: "
"Member must not be null" % pb
)
elif pb["type"] == "bad_decision_type":
messages.append(
"Value '%(value)s' at '%(where)s' failed to satisfy constraint: " \
"Member must satisfy enum value set: " \
"Value '%(value)s' at '%(where)s' failed to satisfy constraint: "
"Member must satisfy enum value set: "
"[%(possible_values)s]" % pb
)
else:

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals
import six
import boto.swf
@ -62,6 +61,48 @@ class SWFBackend(BaseBackend):
domains = reversed(domains)
return domains
def list_open_workflow_executions(self, domain_name, maximum_page_size,
tag_filter, reverse_order, **kwargs):
self._process_timeouts()
domain = self._get_domain(domain_name)
if domain.status == "DEPRECATED":
raise SWFDomainDeprecatedFault(domain_name)
open_wfes = [
wfe for wfe in domain.workflow_executions
if wfe.execution_status == 'OPEN'
]
if tag_filter:
for open_wfe in open_wfes:
if tag_filter['tag'] not in open_wfe.tag_list:
open_wfes.remove(open_wfe)
if reverse_order:
open_wfes = reversed(open_wfes)
return open_wfes[0:maximum_page_size]
def list_closed_workflow_executions(self, domain_name, close_time_filter,
tag_filter, close_status_filter, maximum_page_size, reverse_order,
**kwargs):
self._process_timeouts()
domain = self._get_domain(domain_name)
if domain.status == "DEPRECATED":
raise SWFDomainDeprecatedFault(domain_name)
closed_wfes = [
wfe for wfe in domain.workflow_executions
if wfe.execution_status == 'CLOSED'
]
if tag_filter:
for closed_wfe in closed_wfes:
if tag_filter['tag'] not in closed_wfe.tag_list:
closed_wfes.remove(closed_wfe)
if close_status_filter:
for closed_wfe in closed_wfes:
if close_status_filter != closed_wfe.close_status:
closed_wfes.remove(closed_wfe)
if reverse_order:
closed_wfes = reversed(closed_wfes)
return closed_wfes[0:maximum_page_size]
def register_domain(self, name, workflow_execution_retention_period_in_days,
description=None):
if self._get_domain(name, ignore_empty=True):
@ -109,13 +150,13 @@ class SWFBackend(BaseBackend):
def start_workflow_execution(self, domain_name, workflow_id,
workflow_name, workflow_version,
tag_list=None, **kwargs):
tag_list=None, input=None, **kwargs):
domain = self._get_domain(domain_name)
wf_type = domain.get_type("workflow", workflow_name, workflow_version)
if wf_type.status == "DEPRECATED":
raise SWFTypeDeprecatedFault(wf_type)
wfe = WorkflowExecution(domain, wf_type, workflow_id,
tag_list=tag_list, **kwargs)
tag_list=tag_list, input=input, **kwargs)
domain.add_workflow_execution(wfe)
wfe.start()

View File

@ -92,7 +92,7 @@ class Domain(object):
if not wfe and raise_if_none:
if run_id:
args = ["execution", "WorkflowExecution=[workflowId={0}, runId={1}]".format(
workflow_id, run_id)]
workflow_id, run_id)]
else:
args = ["execution, workflowId = {0}".format(workflow_id)]
raise SWFUnknownResourceFault(*args)
@ -100,7 +100,7 @@ class Domain(object):
return wfe
def add_to_activity_task_list(self, task_list, obj):
if not task_list in self.activity_task_lists:
if task_list not in self.activity_task_lists:
self.activity_task_lists[task_list] = []
self.activity_task_lists[task_list].append(obj)
@ -112,7 +112,7 @@ class Domain(object):
return _all
def add_to_decision_task_list(self, task_list, obj):
if not task_list in self.decision_task_lists:
if task_list not in self.decision_task_lists:
self.decision_task_lists[task_list] = []
self.decision_task_lists[task_list].append(obj)

View File

@ -57,7 +57,7 @@ class WorkflowExecution(object):
self.latest_execution_context = None
self.parent = None
self.start_timestamp = None
self.tag_list = [] # TODO
self.tag_list = kwargs.get("tag_list", None) or []
self.timeout_type = None
self.workflow_type = workflow_type
# args processing
@ -146,6 +146,27 @@ class WorkflowExecution(object):
hsh["latestActivityTaskTimestamp"] = self.latest_activity_task_timestamp
return hsh
def to_list_dict(self):
hsh = {
'execution': {
'workflowId': self.workflow_id,
'runId': self.run_id,
},
'workflowType': self.workflow_type.to_short_dict(),
'startTimestamp': self.start_timestamp,
'executionStatus': self.execution_status,
'cancelRequested': self.cancel_requested,
}
if self.tag_list:
hsh['tagList'] = self.tag_list
if self.parent:
hsh['parent'] = self.parent
if self.close_status:
hsh['closeStatus'] = self.close_status
if self.close_timestamp:
hsh['closeTimestamp'] = self.close_timestamp
return hsh
def _process_timeouts(self):
"""
SWF timeouts can happen on different objects (workflow executions,
@ -233,6 +254,7 @@ class WorkflowExecution(object):
task_list=self.task_list,
task_start_to_close_timeout=self.task_start_to_close_timeout,
workflow_type=self.workflow_type,
input=self.input
)
self.schedule_decision_task()

View File

@ -2,10 +2,8 @@ import json
import six
from moto.core.responses import BaseResponse
from werkzeug.exceptions import HTTPException
from moto.core.utils import camelcase_to_underscores, method_names_from_class
from .exceptions import SWFSerializationException
from .exceptions import SWFSerializationException, SWFValidationException
from .models import swf_backends
@ -20,6 +18,15 @@ class SWFResponse(BaseResponse):
def _params(self):
return json.loads(self.body.decode("utf-8"))
def _check_int(self, parameter):
if not isinstance(parameter, int):
raise SWFSerializationException(parameter)
def _check_float_or_int(self, parameter):
if not isinstance(parameter, float):
if not isinstance(parameter, int):
raise SWFSerializationException(parameter)
def _check_none_or_string(self, parameter):
if parameter is not None:
self._check_string(parameter)
@ -39,6 +46,18 @@ class SWFResponse(BaseResponse):
if not isinstance(i, six.string_types):
raise SWFSerializationException(parameter)
def _check_exclusivity(self, **kwargs):
if list(kwargs.values()).count(None) >= len(kwargs) - 1:
return
keys = kwargs.keys()
if len(keys) == 2:
message = 'Cannot specify both a {0} and a {1}'.format(keys[0],
keys[1])
else:
message = 'Cannot specify more than one exclusive filters in the' \
' same query: {0}'.format(keys)
raise SWFValidationException(message)
def _list_types(self, kind):
domain_name = self._params["domain"]
status = self._params["registrationStatus"]
@ -83,6 +102,102 @@ class SWFResponse(BaseResponse):
"domainInfos": [domain.to_short_dict() for domain in domains]
})
def list_closed_workflow_executions(self):
domain = self._params['domain']
start_time_filter = self._params.get('startTimeFilter', None)
close_time_filter = self._params.get('closeTimeFilter', None)
execution_filter = self._params.get('executionFilter', None)
workflow_id = execution_filter['workflowId'] if execution_filter else None
maximum_page_size = self._params.get('maximumPageSize', 1000)
reverse_order = self._params.get('reverseOrder', None)
tag_filter = self._params.get('tagFilter', None)
type_filter = self._params.get('typeFilter', None)
close_status_filter = self._params.get('closeStatusFilter', None)
self._check_string(domain)
self._check_none_or_string(workflow_id)
self._check_exclusivity(executionFilter=execution_filter,
typeFilter=type_filter,
tagFilter=tag_filter,
closeStatusFilter=close_status_filter)
self._check_exclusivity(startTimeFilter=start_time_filter,
closeTimeFilter=close_time_filter)
if start_time_filter is None and close_time_filter is None:
raise SWFValidationException('Must specify time filter')
if start_time_filter:
self._check_float_or_int(start_time_filter['oldestDate'])
if 'latestDate' in start_time_filter:
self._check_float_or_int(start_time_filter['latestDate'])
if close_time_filter:
self._check_float_or_int(close_time_filter['oldestDate'])
if 'latestDate' in close_time_filter:
self._check_float_or_int(close_time_filter['latestDate'])
if tag_filter:
self._check_string(tag_filter['tag'])
if type_filter:
self._check_string(type_filter['name'])
self._check_string(type_filter['version'])
if close_status_filter:
self._check_string(close_status_filter['status'])
self._check_int(maximum_page_size)
workflow_executions = self.swf_backend.list_closed_workflow_executions(
domain_name=domain,
start_time_filter=start_time_filter,
close_time_filter=close_time_filter,
execution_filter=execution_filter,
tag_filter=tag_filter,
type_filter=type_filter,
maximum_page_size=maximum_page_size,
reverse_order=reverse_order,
workflow_id=workflow_id,
close_status_filter=close_status_filter
)
return json.dumps({
'executionInfos': [wfe.to_list_dict() for wfe in workflow_executions]
})
def list_open_workflow_executions(self):
domain = self._params['domain']
start_time_filter = self._params['startTimeFilter']
execution_filter = self._params.get('executionFilter', None)
workflow_id = execution_filter['workflowId'] if execution_filter else None
maximum_page_size = self._params.get('maximumPageSize', 1000)
reverse_order = self._params.get('reverseOrder', None)
tag_filter = self._params.get('tagFilter', None)
type_filter = self._params.get('typeFilter', None)
self._check_string(domain)
self._check_none_or_string(workflow_id)
self._check_exclusivity(executionFilter=execution_filter,
typeFilter=type_filter,
tagFilter=tag_filter)
self._check_float_or_int(start_time_filter['oldestDate'])
if 'latestDate' in start_time_filter:
self._check_float_or_int(start_time_filter['latestDate'])
if tag_filter:
self._check_string(tag_filter['tag'])
if type_filter:
self._check_string(type_filter['name'])
self._check_string(type_filter['version'])
self._check_int(maximum_page_size)
workflow_executions = self.swf_backend.list_open_workflow_executions(
domain_name=domain,
start_time_filter=start_time_filter,
execution_filter=execution_filter,
tag_filter=tag_filter,
type_filter=type_filter,
maximum_page_size=maximum_page_size,
reverse_order=reverse_order,
workflow_id=workflow_id
)
return json.dumps({
'executionInfos': [wfe.to_list_dict() for wfe in workflow_executions]
})
def register_domain(self):
name = self._params["name"]
retention = self._params["workflowExecutionRetentionPeriodInDays"]
@ -90,14 +205,14 @@ class SWFResponse(BaseResponse):
self._check_string(retention)
self._check_string(name)
self._check_none_or_string(description)
domain = self.swf_backend.register_domain(name, retention,
description=description)
self.swf_backend.register_domain(name, retention,
description=description)
return ""
def deprecate_domain(self):
name = self._params["name"]
self._check_string(name)
domain = self.swf_backend.deprecate_domain(name)
self.swf_backend.deprecate_domain(name)
return ""
def describe_domain(self):
@ -136,7 +251,7 @@ class SWFResponse(BaseResponse):
self._check_none_or_string(description)
# TODO: add defaultTaskPriority when boto gets to support it
activity_type = self.swf_backend.register_type(
self.swf_backend.register_type(
"activity", domain, name, version, task_list=task_list,
default_task_heartbeat_timeout=default_task_heartbeat_timeout,
default_task_schedule_to_close_timeout=default_task_schedule_to_close_timeout,
@ -180,7 +295,7 @@ class SWFResponse(BaseResponse):
# TODO: add defaultTaskPriority when boto gets to support it
# TODO: add defaultLambdaRole when boto gets to support it
workflow_type = self.swf_backend.register_type(
self.swf_backend.register_type(
"workflow", domain, name, version, task_list=task_list,
default_child_policy=default_child_policy,
default_task_start_to_close_timeout=default_task_start_to_close_timeout,

View File

@ -1,5 +1,4 @@
from freezegun import freeze_time
from sure import expect
from moto.swf.exceptions import SWFWorkflowExecutionClosedError
from moto.swf.models import (
@ -43,9 +42,9 @@ def test_activity_task_creation():
task.fail()
task.state.should.equal("FAILED")
def test_activity_task_full_dict_representation():
wfe = make_workflow_execution()
wft = wfe.workflow_type
at = ActivityTask(
activity_id="my-activity-123",
activity_type=ActivityType("foo", "v1.0"),
@ -68,6 +67,7 @@ def test_activity_task_full_dict_representation():
fd = at.to_full_dict()
fd["startedEventId"].should.equal(1234)
def test_activity_task_reset_heartbeat_clock():
wfe = make_workflow_execution()
@ -88,6 +88,7 @@ def test_activity_task_reset_heartbeat_clock():
task.last_heartbeat_timestamp.should.equal(1420117200.0)
def test_activity_task_first_timeout():
wfe = make_workflow_execution()
@ -109,6 +110,7 @@ def test_activity_task_first_timeout():
task.state.should.equal("TIMED_OUT")
task.timeout_type.should.equal("HEARTBEAT")
def test_activity_task_cannot_timeout_on_closed_workflow_execution():
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution()
@ -130,6 +132,7 @@ def test_activity_task_cannot_timeout_on_closed_workflow_execution():
process_first_timeout(wfe)
task.first_timeout().should.be.none
def test_activity_task_cannot_change_state_on_closed_workflow_execution():
wfe = make_workflow_execution()
wfe.start()

View File

@ -16,6 +16,7 @@ def test_decision_task_creation():
dt.task_token.should_not.be.empty
dt.started_event_id.should.be.none
def test_decision_task_full_dict_representation():
wfe = make_workflow_execution()
wft = wfe.workflow_type
@ -33,6 +34,7 @@ def test_decision_task_full_dict_representation():
fd = dt.to_full_dict()
fd["startedEventId"].should.equal(1234)
def test_decision_task_first_timeout():
wfe = make_workflow_execution()
dt = DecisionTask(wfe, 123)
@ -49,6 +51,7 @@ def test_decision_task_first_timeout():
dt.complete()
dt.first_timeout().should.be.none
def test_decision_task_cannot_timeout_on_closed_workflow_execution():
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution()
@ -64,6 +67,7 @@ def test_decision_task_cannot_timeout_on_closed_workflow_execution():
process_first_timeout(wfe)
dt.first_timeout().should.be.none
def test_decision_task_cannot_change_state_on_closed_workflow_execution():
wfe = make_workflow_execution()
wfe.start()

View File

@ -1,12 +1,10 @@
from collections import namedtuple
from sure import expect
from moto.swf.exceptions import SWFUnknownResourceFault
from moto.swf.models import Domain
# Ensure 'assert_raises' context manager support for Python 2.6
import tests.backport_assert_raises # noqa
from nose.tools import assert_raises
# Fake WorkflowExecution for tests purposes
WorkflowExecution = namedtuple(
@ -17,11 +15,12 @@ WorkflowExecution = namedtuple(
def test_domain_short_dict_representation():
domain = Domain("foo", "52")
domain.to_short_dict().should.equal({"name":"foo", "status":"REGISTERED"})
domain.to_short_dict().should.equal({"name": "foo", "status": "REGISTERED"})
domain.description = "foo bar"
domain.to_short_dict()["description"].should.equal("foo bar")
def test_domain_full_dict_representation():
domain = Domain("foo", "52")
@ -29,10 +28,12 @@ def test_domain_full_dict_representation():
_config = domain.to_full_dict()["configuration"]
_config["workflowExecutionRetentionPeriodInDays"].should.equal("52")
def test_domain_string_representation():
domain = Domain("my-domain", "60")
str(domain).should.equal("Domain(name: my-domain, status: REGISTERED)")
def test_domain_add_to_activity_task_list():
domain = Domain("my-domain", "60")
domain.add_to_activity_task_list("foo", "bar")
@ -40,12 +41,14 @@ def test_domain_add_to_activity_task_list():
"foo": ["bar"]
})
def test_domain_activity_tasks():
domain = Domain("my-domain", "60")
domain.add_to_activity_task_list("foo", "bar")
domain.add_to_activity_task_list("other", "baz")
sorted(domain.activity_tasks).should.equal(["bar", "baz"])
def test_domain_add_to_decision_task_list():
domain = Domain("my-domain", "60")
domain.add_to_decision_task_list("foo", "bar")
@ -53,12 +56,14 @@ def test_domain_add_to_decision_task_list():
"foo": ["bar"]
})
def test_domain_decision_tasks():
domain = Domain("my-domain", "60")
domain.add_to_decision_task_list("foo", "bar")
domain.add_to_decision_task_list("other", "baz")
sorted(domain.decision_tasks).should.equal(["bar", "baz"])
def test_domain_get_workflow_execution():
domain = Domain("my-domain", "60")

View File

@ -1,5 +1,3 @@
from sure import expect
from moto.swf.models import GenericType
@ -18,6 +16,7 @@ def test_type_short_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_short_dict().should.equal({"name": "test-foo", "version": "v1.0"})
def test_type_medium_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_medium_dict()["fooType"].should.equal(_type.to_short_dict())
@ -32,13 +31,14 @@ def test_type_medium_dict_representation():
_type.status = "DEPRECATED"
_type.to_medium_dict().should.contain("deprecationDate")
def test_type_full_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_full_dict()["typeInfo"].should.equal(_type.to_medium_dict())
_type.to_full_dict()["configuration"].should.equal({})
_type.task_list = "foo"
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name":"foo"})
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name": "foo"})
_type.just_an_example_timeout = "60"
_type.to_full_dict()["configuration"]["justAnExampleTimeout"].should.equal("60")
@ -47,6 +47,7 @@ def test_type_full_dict_representation():
keys = _type.to_full_dict()["configuration"].keys()
sorted(keys).should.equal(["defaultTaskList", "justAnExampleTimeout"])
def test_type_string_representation():
_type = FooType("test-foo", "v1.0")
str(_type).should.equal("FooType(name: test-foo, version: v1.0, status: REGISTERED)")

View File

@ -1,4 +1,3 @@
from sure import expect
from freezegun import freeze_time
from moto.swf.models import HistoryEvent
@ -11,6 +10,7 @@ def test_history_event_creation():
he.event_type.should.equal("DecisionTaskStarted")
he.event_timestamp.should.equal(1420113600.0)
@freeze_time("2015-01-01 12:00:00")
def test_history_event_to_dict_representation():
he = HistoryEvent(123, "DecisionTaskStarted", scheduled_event_id=2)
@ -23,6 +23,7 @@ def test_history_event_to_dict_representation():
}
})
def test_history_event_breaks_on_initialization_if_not_implemented():
HistoryEvent.when.called_with(
123, "UnknownHistoryEvent"

View File

@ -1,10 +1,10 @@
from freezegun import freeze_time
from sure import expect
from moto.swf.models import Timeout, WorkflowExecution
from moto.swf.models import Timeout
from ..utils import make_workflow_execution
def test_timeout_creation():
wfe = make_workflow_execution()

View File

@ -1,5 +1,5 @@
from sure import expect
from freezegun import freeze_time
import sure # noqa
from moto.swf.models import (
ActivityType,
@ -18,14 +18,15 @@ from ..utils import (
VALID_ACTIVITY_TASK_ATTRIBUTES = {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.1" },
"taskList": { "name": "task-list-name" },
"activityType": {"name": "test-activity", "version": "v1.1"},
"taskList": {"name": "task-list-name"},
"scheduleToStartTimeout": "600",
"scheduleToCloseTimeout": "600",
"startToCloseTimeout": "600",
"heartbeatTimeout": "300",
}
def test_workflow_execution_creation():
domain = get_basic_domain()
wft = get_basic_workflow_type()
@ -35,6 +36,7 @@ def test_workflow_execution_creation():
wfe.workflow_type.should.equal(wft)
wfe.child_policy.should.equal("TERMINATE")
def test_workflow_execution_creation_child_policy_logic():
domain = get_basic_domain()
@ -65,10 +67,12 @@ def test_workflow_execution_creation_child_policy_logic():
WorkflowType("test-workflow", "v1.0"), "ab1234"
).should.throw(SWFDefaultUndefinedFault)
def test_workflow_execution_string_representation():
wfe = make_workflow_execution(child_policy="TERMINATE")
str(wfe).should.match(r"^WorkflowExecution\(run_id: .*\)")
def test_workflow_execution_generates_a_random_run_id():
domain = get_basic_domain()
wft = get_basic_workflow_type()
@ -76,6 +80,7 @@ def test_workflow_execution_generates_a_random_run_id():
wfe2 = WorkflowExecution(domain, wft, "ab1235", child_policy="TERMINATE")
wfe1.run_id.should_not.equal(wfe2.run_id)
def test_workflow_execution_short_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -90,6 +95,7 @@ def test_workflow_execution_short_dict_representation():
sd["workflowId"].should.equal("ab1234")
sd.should.contain("runId")
def test_workflow_execution_medium_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -112,6 +118,7 @@ def test_workflow_execution_medium_dict_representation():
md = wfe.to_medium_dict()
md["tagList"].should.equal(["foo", "bar", "baz"])
def test_workflow_execution_full_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
@ -134,12 +141,34 @@ def test_workflow_execution_full_dict_representation():
"taskStartToCloseTimeout": "300",
})
def test_workflow_execution_list_dict_representation():
domain = get_basic_domain()
wf_type = WorkflowType(
'test-workflow', 'v1.0',
task_list='queue', default_child_policy='ABANDON',
default_execution_start_to_close_timeout='300',
default_task_start_to_close_timeout='300',
)
wfe = WorkflowExecution(domain, wf_type, 'ab1234')
ld = wfe.to_list_dict()
ld['workflowType']['version'].should.equal('v1.0')
ld['workflowType']['name'].should.equal('test-workflow')
ld['executionStatus'].should.equal('OPEN')
ld['execution']['workflowId'].should.equal('ab1234')
ld['execution'].should.contain('runId')
ld['cancelRequested'].should.be.false
ld.should.contain('startTimestamp')
def test_workflow_execution_schedule_decision_task():
wfe = make_workflow_execution()
wfe.open_counts["openDecisionTasks"].should.equal(0)
wfe.schedule_decision_task()
wfe.open_counts["openDecisionTasks"].should.equal(1)
def test_workflow_execution_start_decision_task():
wfe = make_workflow_execution()
wfe.schedule_decision_task()
@ -150,6 +179,7 @@ def test_workflow_execution_start_decision_task():
wfe.events()[-1].event_type.should.equal("DecisionTaskStarted")
wfe.events()[-1].event_attributes["identity"].should.equal("srv01")
def test_workflow_execution_history_events_ids():
wfe = make_workflow_execution()
wfe._add_event("WorkflowExecutionStarted")
@ -158,6 +188,7 @@ def test_workflow_execution_history_events_ids():
ids = [evt.event_id for evt in wfe.events()]
ids.should.equal([1, 2, 3])
@freeze_time("2015-01-01 12:00:00")
def test_workflow_execution_start():
wfe = make_workflow_execution()
@ -169,6 +200,7 @@ def test_workflow_execution_start():
wfe.events()[0].event_type.should.equal("WorkflowExecutionStarted")
wfe.events()[1].event_type.should.equal("DecisionTaskScheduled")
@freeze_time("2015-01-02 12:00:00")
def test_workflow_execution_complete():
wfe = make_workflow_execution()
@ -181,6 +213,7 @@ def test_workflow_execution_complete():
wfe.events()[-1].event_attributes["decisionTaskCompletedEventId"].should.equal(123)
wfe.events()[-1].event_attributes["result"].should.equal("foo")
@freeze_time("2015-01-02 12:00:00")
def test_workflow_execution_fail():
wfe = make_workflow_execution()
@ -194,6 +227,7 @@ def test_workflow_execution_fail():
wfe.events()[-1].event_attributes["details"].should.equal("some details")
wfe.events()[-1].event_attributes["reason"].should.equal("my rules")
@freeze_time("2015-01-01 12:00:00")
def test_workflow_execution_schedule_activity_task():
wfe = make_workflow_execution()
@ -215,6 +249,7 @@ def test_workflow_execution_schedule_activity_task():
task.activity_type.name.should.equal("test-activity")
wfe.domain.activity_task_lists["task-list-name"].should.contain(task)
def test_workflow_execution_schedule_activity_task_without_task_list_should_take_default():
wfe = make_workflow_execution()
wfe.domain.add_type(
@ -222,7 +257,7 @@ def test_workflow_execution_schedule_activity_task_without_task_list_should_take
)
wfe.schedule_activity_task(123, {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.2" },
"activityType": {"name": "test-activity", "version": "v1.2"},
"scheduleToStartTimeout": "600",
"scheduleToCloseTimeout": "600",
"startToCloseTimeout": "600",
@ -237,6 +272,7 @@ def test_workflow_execution_schedule_activity_task_without_task_list_should_take
task = wfe.activity_tasks[0]
wfe.domain.activity_task_lists["foobar"].should.contain(task)
def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attributes():
wfe = make_workflow_execution()
at = ActivityType("test-activity", "v1.1")
@ -246,7 +282,7 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
hsh = {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exists", "version": "v1.1" },
"activityType": {"name": "test-activity-does-not-exists", "version": "v1.1"},
}
wfe.schedule_activity_task(123, hsh)
@ -266,7 +302,7 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_TASK_LIST_UNDEFINED")
hsh["taskList"] = { "name": "foobar" }
hsh["taskList"] = {"name": "foobar"}
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
@ -304,29 +340,37 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
wfe.open_counts["openDecisionTasks"].should.equal(0)
wfe.open_counts["openActivityTasks"].should.equal(1)
def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision():
wfe = make_workflow_execution()
wfe.start()
task_token = wfe.decision_tasks[-1].task_token
wfe.start_decision_task(task_token)
wfe.complete_decision_task(task_token,
execution_context="free-form execution context",
decisions=[
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exist", "version": "v1.2" },
}
},
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity-does-not-exist", "version": "v1.2" },
}
},
])
wfe.complete_decision_task(
task_token,
execution_context="free-form execution context",
decisions=[
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity-does-not-exist",
"version": "v1.2"
},
}
},
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity-does-not-exist",
"version": "v1.2"
},
}
},
])
wfe.latest_execution_context.should.equal("free-form execution context")
wfe.open_counts["openActivityTasks"].should.equal(0)
@ -336,6 +380,7 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision
last_events[1].event_type.should.equal("ScheduleActivityTaskFailed")
last_events[2].event_type.should.equal("DecisionTaskScheduled")
def test_workflow_execution_schedule_activity_task_with_same_activity_id():
wfe = make_workflow_execution()
@ -350,6 +395,7 @@ def test_workflow_execution_schedule_activity_task_with_same_activity_id():
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("ACTIVITY_ID_ALREADY_IN_USE")
def test_workflow_execution_start_activity_task():
wfe = make_workflow_execution()
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
@ -360,6 +406,7 @@ def test_workflow_execution_start_activity_task():
wfe.events()[-1].event_type.should.equal("ActivityTaskStarted")
wfe.events()[-1].event_attributes["identity"].should.equal("worker01")
def test_complete_activity_task():
wfe = make_workflow_execution()
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
@ -379,6 +426,7 @@ def test_complete_activity_task():
wfe.open_counts["openActivityTasks"].should.equal(0)
wfe.open_counts["openDecisionTasks"].should.equal(1)
def test_terminate():
wfe = make_workflow_execution()
wfe.schedule_decision_task()
@ -394,6 +442,7 @@ def test_terminate():
# take default child_policy if not provided (as here)
last_event.event_attributes["childPolicy"].should.equal("ABANDON")
def test_first_timeout():
wfe = make_workflow_execution()
wfe.first_timeout().should.be.none
@ -406,6 +455,7 @@ def test_first_timeout():
# 2 hours timeout reached
wfe.first_timeout().should.be.a(Timeout)
# See moto/swf/models/workflow_execution.py "_process_timeouts()" for more details
def test_timeouts_are_processed_in_order_and_reevaluated():
# Let's make a Workflow Execution with the following properties:
@ -420,8 +470,8 @@ def test_timeouts_are_processed_in_order_and_reevaluated():
# - but the last scheduled decision task should *not* timeout (workflow closed)
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution(
execution_start_to_close_timeout=8*60,
task_start_to_close_timeout=5*60,
execution_start_to_close_timeout=8 * 60,
task_start_to_close_timeout=5 * 60,
)
# decision will automatically start
wfe = auto_start_decision_tasks(wfe)

View File

@ -1,7 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
from moto.swf import swf_backend
@ -24,15 +22,17 @@ def test_poll_for_activity_task_when_one():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted")
resp["events"][-1]["activityTaskStartedEventAttributes"].should.equal(
{ "identity": "surprise", "scheduledEventId": 5 }
{"identity": "surprise", "scheduledEventId": 5}
)
@mock_swf
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})
@mock_swf
def test_poll_for_activity_task_on_non_existent_queue():
conn = setup_workflow()
@ -52,6 +52,7 @@ def test_count_pending_activity_tasks():
resp = conn.count_pending_activity_tasks("test-domain", "activity-task-list")
resp.should.equal({"count": 1, "truncated": False})
@mock_swf
def test_count_pending_decision_tasks_on_non_existent_task_list():
conn = setup_workflow()
@ -75,20 +76,9 @@ def test_respond_activity_task_completed():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskCompleted")
resp["events"][-2]["activityTaskCompletedEventAttributes"].should.equal(
{ "result": "result of the task", "scheduledEventId": 5, "startedEventId": 6 }
{"result": "result of the task", "scheduledEventId": 5, "startedEventId": 6}
)
@mock_swf
def test_respond_activity_task_completed_with_wrong_token():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
conn.poll_for_activity_task("test-domain", "activity-task-list")
conn.respond_activity_task_completed.when.called_with(
"not-a-correct-token"
).should.throw(SWFResponseError, "Invalid token")
@mock_swf
def test_respond_activity_task_completed_on_closed_workflow_execution():
@ -108,6 +98,7 @@ def test_respond_activity_task_completed_on_closed_workflow_execution():
activity_token
).should.throw(SWFResponseError, "WorkflowExecution=")
@mock_swf
def test_respond_activity_task_completed_with_task_already_completed():
conn = setup_workflow()
@ -142,10 +133,11 @@ def test_respond_activity_task_failed():
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskFailed")
resp["events"][-2]["activityTaskFailedEventAttributes"].should.equal(
{ "reason": "short reason", "details": "long details",
"scheduledEventId": 5, "startedEventId": 6 }
{"reason": "short reason", "details": "long details",
"scheduledEventId": 5, "startedEventId": 6}
)
@mock_swf
def test_respond_activity_task_completed_with_wrong_token():
# NB: we just test ONE failure case for RespondActivityTaskFailed
@ -175,6 +167,7 @@ def test_record_activity_task_heartbeat():
resp = conn.record_activity_task_heartbeat(activity_token)
resp.should.equal({"cancelRequested": False})
@mock_swf
def test_record_activity_task_heartbeat_with_wrong_token():
conn = setup_workflow()
@ -188,6 +181,7 @@ def test_record_activity_task_heartbeat_with_wrong_token():
"bad-token", details="some progress details"
).should.throw(SWFResponseError)
@mock_swf
def test_record_activity_task_heartbeat_sets_details_in_case_of_timeout():
conn = setup_workflow()

View File

@ -1,6 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from sure import expect
from moto import mock_swf
@ -17,6 +16,7 @@ def test_register_activity_type():
actype["activityType"]["name"].should.equal("test-activity")
actype["activityType"]["version"].should.equal("v1.0")
@mock_swf
def test_register_already_existing_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_activity_type():
"test-domain", "test-activity", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -36,6 +37,7 @@ def test_register_with_wrong_parameter_type():
"test-domain", "test-activity", 12
).should.throw(SWFResponseError)
# ListActivityTypes endpoint
@mock_swf
def test_list_activity_types():
@ -49,6 +51,7 @@ def test_list_activity_types():
names = [activity_type["activityType"]["name"] for activity_type in all_activity_types["typeInfos"]]
names.should.equal(["a-test-activity", "b-test-activity", "c-test-activity"])
@mock_swf
def test_list_activity_types_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -76,6 +79,7 @@ def test_deprecate_activity_type():
actype["activityType"]["name"].should.equal("test-activity")
actype["activityType"]["version"].should.equal("v1.0")
@mock_swf
def test_deprecate_already_deprecated_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -87,6 +91,7 @@ def test_deprecate_already_deprecated_activity_type():
"test-domain", "test-activity", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -96,6 +101,7 @@ def test_deprecate_non_existent_activity_type():
"test-domain", "non-existent", "v1.0"
).should.throw(SWFResponseError)
# DescribeActivityType endpoint
@mock_swf
def test_describe_activity_type():
@ -111,6 +117,7 @@ def test_describe_activity_type():
infos["activityType"]["version"].should.equal("v1.0")
infos["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_activity_type():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,7 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
from moto.swf import swf_backend
@ -24,6 +22,7 @@ def test_poll_for_decision_task_when_one():
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01")
@mock_swf
def test_poll_for_decision_task_when_none():
conn = setup_workflow()
@ -34,12 +33,14 @@ def test_poll_for_decision_task_when_none():
# after waiting 60s when there's no decision to be taken
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
@mock_swf
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})
@mock_swf
def test_poll_for_decision_task_with_reverse_order():
conn = setup_workflow()
@ -56,12 +57,14 @@ def test_count_pending_decision_tasks():
resp = conn.count_pending_decision_tasks("test-domain", "queue")
resp.should.equal({"count": 1, "truncated": False})
@mock_swf
def test_count_pending_decision_tasks_on_non_existent_task_list():
conn = setup_workflow()
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()
@ -104,14 +107,16 @@ def test_respond_decision_task_completed_with_no_decision():
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp["latestExecutionContext"].should.equal("free-form context")
@mock_swf
def test_respond_decision_task_completed_with_wrong_token():
conn = setup_workflow()
resp = conn.poll_for_decision_task("test-domain", "queue")
conn.poll_for_decision_task("test-domain", "queue")
conn.respond_decision_task_completed.when.called_with(
"not-a-correct-token"
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_on_close_workflow_execution():
conn = setup_workflow()
@ -127,6 +132,7 @@ def test_respond_decision_task_completed_on_close_workflow_execution():
task_token
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_with_task_already_completed():
conn = setup_workflow()
@ -138,6 +144,7 @@ def test_respond_decision_task_completed_with_task_already_completed():
task_token
).should.throw(SWFResponseError)
@mock_swf
def test_respond_decision_task_completed_with_complete_workflow_execution():
conn = setup_workflow()
@ -162,6 +169,7 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
])
resp["events"][-1]["workflowExecutionCompletedEventAttributes"]["result"].should.equal("foo bar")
@mock_swf
def test_respond_decision_task_completed_with_close_decision_not_last():
conn = setup_workflow()
@ -169,14 +177,15 @@ def test_respond_decision_task_completed_with_close_decision_not_last():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "CompleteWorkflowExecution" },
{ "decisionType": "WeDontCare" },
{"decisionType": "CompleteWorkflowExecution"},
{"decisionType": "WeDontCare"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(SWFResponseError, r"Close must be last decision in list")
@mock_swf
def test_respond_decision_task_completed_with_invalid_decision_type():
conn = setup_workflow()
@ -184,16 +193,16 @@ def test_respond_decision_task_completed_with_invalid_decision_type():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "BadDecisionType" },
{ "decisionType": "CompleteWorkflowExecution" },
{"decisionType": "BadDecisionType"},
{"decisionType": "CompleteWorkflowExecution"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
task_token, decisions=decisions).should.throw(
SWFResponseError,
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'"
)
)
@mock_swf
def test_respond_decision_task_completed_with_missing_attributes():
@ -210,11 +219,12 @@ def test_respond_decision_task_completed_with_missing_attributes():
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " \
r"failed to satisfy constraint: Member must not be null"
)
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
r"failed to satisfy constraint: Member must not be null"
)
@mock_swf
def test_respond_decision_task_completed_with_missing_attributes_totally():
@ -223,16 +233,17 @@ def test_respond_decision_task_completed_with_missing_attributes_totally():
task_token = resp["taskToken"]
decisions = [
{ "decisionType": "StartTimer" },
{"decisionType": "StartTimer"},
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' " \
r"failed to satisfy constraint: Member must not be null"
)
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
r"failed to satisfy constraint: Member must not be null"
)
@mock_swf
def test_respond_decision_task_completed_with_fail_workflow_execution():
@ -260,6 +271,7 @@ def test_respond_decision_task_completed_with_fail_workflow_execution():
attrs["reason"].should.equal("my rules")
attrs["details"].should.equal("foo")
@mock_swf
@freeze_time("2015-01-01 12:00:00")
def test_respond_decision_task_completed_with_schedule_activity_task():

View File

@ -1,6 +1,5 @@
import boto
from boto.swf.exceptions import SWFResponseError
from sure import expect
from moto import mock_swf
@ -18,6 +17,7 @@ def test_register_domain():
domain["status"].should.equal("REGISTERED")
domain["description"].should.equal("A test domain")
@mock_swf
def test_register_already_existing_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_domain():
"test-domain", "60", description="A test domain"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -48,6 +49,7 @@ def test_list_domains_order():
names = [domain["name"] for domain in all_domains["domainInfos"]]
names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"])
@mock_swf
def test_list_domains_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -72,6 +74,7 @@ def test_deprecate_domain():
domain["name"].should.equal("test-domain")
@mock_swf
def test_deprecate_already_deprecated_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -82,6 +85,7 @@ def test_deprecate_already_deprecated_domain():
"test-domain"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")
@ -103,6 +107,7 @@ def test_describe_domain():
domain["domainInfo"]["name"].should.equal("test-domain")
domain["domainInfo"]["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,6 +1,4 @@
import boto
from freezegun import freeze_time
from sure import expect
from moto import mock_swf
@ -35,6 +33,7 @@ def test_activity_task_heartbeat_timeout():
resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled")
# Decision Task Start to Close timeout
# Default value in workflow helpers: 5 mins
@mock_swf
@ -68,6 +67,7 @@ def test_decision_task_start_to_close_timeout():
# checks that event has been emitted at 12:05:00, not 12:05:30
resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0)
# Workflow Execution Start to Close timeout
# Default value in workflow helpers: 2 hours
@mock_swf

View File

@ -1,12 +1,13 @@
import boto
from boto.swf.exceptions import SWFResponseError
from datetime import datetime, timedelta
import sure # noqa
# Ensure 'assert_raises' context manager support for Python 2.6
import tests.backport_assert_raises # noqa
from nose.tools import assert_raises
from sure import expect
from moto import mock_swf
from moto.core.utils import unix_time
# Utils
@ -32,6 +33,7 @@ def test_start_workflow_execution():
wf = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
wf.should.contain("runId")
@mock_swf
def test_start_already_started_workflow_execution():
conn = setup_swf_environment()
@ -41,6 +43,7 @@ def test_start_already_started_workflow_execution():
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_start_workflow_execution_on_deprecated_type():
conn = setup_swf_environment()
@ -62,6 +65,7 @@ def test_describe_workflow_execution():
wfe["executionInfo"]["execution"]["workflowId"].should.equal("uid-abcd1234")
wfe["executionInfo"]["executionStatus"].should.equal("OPEN")
@mock_swf
def test_describe_non_existent_workflow_execution():
conn = setup_swf_environment()
@ -82,6 +86,7 @@ def test_get_workflow_execution_history():
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
@mock_swf
def test_get_workflow_execution_history_with_reverse_order():
conn = setup_swf_environment()
@ -93,6 +98,7 @@ def test_get_workflow_execution_history_with_reverse_order():
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["DecisionTaskScheduled", "WorkflowExecutionStarted"])
@mock_swf
def test_get_workflow_execution_history_on_non_existent_workflow_execution():
conn = setup_swf_environment()
@ -102,6 +108,75 @@ def test_get_workflow_execution_history_on_non_existent_workflow_execution():
).should.throw(SWFResponseError)
# ListOpenWorkflowExecutions endpoint
@mock_swf
def test_list_open_workflow_executions():
conn = setup_swf_environment()
# One open workflow execution
conn.start_workflow_execution(
'test-domain', 'uid-abcd1234', 'test-workflow', 'v1.0'
)
# One closed workflow execution to make sure it isn't displayed
run_id = conn.start_workflow_execution(
'test-domain', 'uid-abcd12345', 'test-workflow', 'v1.0'
)['runId']
conn.terminate_workflow_execution('test-domain', 'uid-abcd12345',
details='some details',
reason='a more complete reason',
run_id=run_id)
yesterday = datetime.now() - timedelta(days=1)
oldest_date = unix_time(yesterday)
response = conn.list_open_workflow_executions('test-domain',
oldest_date,
workflow_id='test-workflow')
execution_infos = response['executionInfos']
len(execution_infos).should.equal(1)
open_workflow = execution_infos[0]
open_workflow['workflowType'].should.equal({'version': 'v1.0',
'name': 'test-workflow'})
open_workflow.should.contain('startTimestamp')
open_workflow['execution']['workflowId'].should.equal('uid-abcd1234')
open_workflow['execution'].should.contain('runId')
open_workflow['cancelRequested'].should.be(False)
open_workflow['executionStatus'].should.equal('OPEN')
# ListClosedWorkflowExecutions endpoint
@mock_swf
def test_list_closed_workflow_executions():
conn = setup_swf_environment()
# Leave one workflow execution open to make sure it isn't displayed
conn.start_workflow_execution(
'test-domain', 'uid-abcd1234', 'test-workflow', 'v1.0'
)
# One closed workflow execution
run_id = conn.start_workflow_execution(
'test-domain', 'uid-abcd12345', 'test-workflow', 'v1.0'
)['runId']
conn.terminate_workflow_execution('test-domain', 'uid-abcd12345',
details='some details',
reason='a more complete reason',
run_id=run_id)
yesterday = datetime.now() - timedelta(days=1)
oldest_date = unix_time(yesterday)
response = conn.list_closed_workflow_executions(
'test-domain',
start_oldest_date=oldest_date,
workflow_id='test-workflow')
execution_infos = response['executionInfos']
len(execution_infos).should.equal(1)
open_workflow = execution_infos[0]
open_workflow['workflowType'].should.equal({'version': 'v1.0',
'name': 'test-workflow'})
open_workflow.should.contain('startTimestamp')
open_workflow['execution']['workflowId'].should.equal('uid-abcd12345')
open_workflow['execution'].should.contain('runId')
open_workflow['cancelRequested'].should.be(False)
open_workflow['executionStatus'].should.equal('CLOSED')
# TerminateWorkflowExecution endpoint
@mock_swf
def test_terminate_workflow_execution():
@ -124,6 +199,7 @@ def test_terminate_workflow_execution():
attrs["reason"].should.equal("a more complete reason")
attrs["cause"].should.equal("OPERATOR_INITIATED")
@mock_swf
def test_terminate_workflow_execution_with_wrong_workflow_or_run_id():
conn = setup_swf_environment()
@ -132,7 +208,7 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id():
)["runId"]
# terminate workflow execution
resp = conn.terminate_workflow_execution("test-domain", "uid-abcd1234")
conn.terminate_workflow_execution("test-domain", "uid-abcd1234")
# already closed, with run_id
conn.terminate_workflow_execution.when.called_with(

View File

@ -1,5 +1,4 @@
import boto
from sure import expect
from moto import mock_swf
from boto.swf.exceptions import SWFResponseError
@ -17,6 +16,7 @@ def test_register_workflow_type():
actype["workflowType"]["name"].should.equal("test-workflow")
actype["workflowType"]["version"].should.equal("v1.0")
@mock_swf
def test_register_already_existing_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -27,6 +27,7 @@ def test_register_already_existing_workflow_type():
"test-domain", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_register_with_wrong_parameter_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -50,6 +51,7 @@ def test_list_workflow_types():
names = [activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"]]
names.should.equal(["a-test-workflow", "b-test-workflow", "c-test-workflow"])
@mock_swf
def test_list_workflow_types_reverse_order():
conn = boto.connect_swf("the_key", "the_secret")
@ -77,6 +79,7 @@ def test_deprecate_workflow_type():
actype["workflowType"]["name"].should.equal("test-workflow")
actype["workflowType"]["version"].should.equal("v1.0")
@mock_swf
def test_deprecate_already_deprecated_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -88,6 +91,7 @@ def test_deprecate_already_deprecated_workflow_type():
"test-domain", "test-workflow", "v1.0"
).should.throw(SWFResponseError)
@mock_swf
def test_deprecate_non_existent_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
@ -115,6 +119,7 @@ def test_describe_workflow_type():
infos["workflowType"]["version"].should.equal("v1.0")
infos["status"].should.equal("REGISTERED")
@mock_swf
def test_describe_non_existent_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals
import json
import sure
from moto.swf.exceptions import (
SWFClientError,
@ -20,6 +19,7 @@ from moto.swf.models import (
WorkflowType,
)
def test_swf_client_error():
ex = SWFClientError("ASpecificType", "error message")
@ -29,6 +29,7 @@ def test_swf_client_error():
"message": "error message"
})
def test_swf_unknown_resource_fault():
ex = SWFUnknownResourceFault("type", "detail")
@ -38,6 +39,7 @@ def test_swf_unknown_resource_fault():
"message": "Unknown type: detail"
})
def test_swf_unknown_resource_fault_with_only_one_parameter():
ex = SWFUnknownResourceFault("foo bar baz")
@ -47,6 +49,7 @@ def test_swf_unknown_resource_fault_with_only_one_parameter():
"message": "Unknown foo bar baz"
})
def test_swf_domain_already_exists_fault():
ex = SWFDomainAlreadyExistsFault("domain-name")
@ -56,6 +59,7 @@ def test_swf_domain_already_exists_fault():
"message": "domain-name"
})
def test_swf_domain_deprecated_fault():
ex = SWFDomainDeprecatedFault("domain-name")
@ -65,6 +69,7 @@ def test_swf_domain_deprecated_fault():
"message": "domain-name"
})
def test_swf_serialization_exception():
ex = SWFSerializationException("value")
@ -74,6 +79,7 @@ def test_swf_serialization_exception():
"message": "class java.lang.Foo can not be converted to an String (not a real SWF exception ; happened on: value)"
})
def test_swf_type_already_exists_fault():
wft = WorkflowType("wf-name", "wf-version")
ex = SWFTypeAlreadyExistsFault(wft)
@ -84,6 +90,7 @@ def test_swf_type_already_exists_fault():
"message": "WorkflowType=[name=wf-name, version=wf-version]"
})
def test_swf_type_deprecated_fault():
wft = WorkflowType("wf-name", "wf-version")
ex = SWFTypeDeprecatedFault(wft)
@ -94,6 +101,7 @@ def test_swf_type_deprecated_fault():
"message": "WorkflowType=[name=wf-name, version=wf-version]"
})
def test_swf_workflow_execution_already_started_fault():
ex = SWFWorkflowExecutionAlreadyStartedFault()
@ -103,6 +111,7 @@ def test_swf_workflow_execution_already_started_fault():
'message': 'Already Started',
})
def test_swf_default_undefined_fault():
ex = SWFDefaultUndefinedFault("execution_start_to_close_timeout")
@ -112,6 +121,7 @@ def test_swf_default_undefined_fault():
"message": "executionStartToCloseTimeout",
})
def test_swf_validation_exception():
ex = SWFValidationException("Invalid token")
@ -121,14 +131,15 @@ def test_swf_validation_exception():
"message": "Invalid token",
})
def test_swf_decision_validation_error():
ex = SWFDecisionValidationException([
{ "type": "null_value",
"where": "decisions.1.member.startTimerDecisionAttributes.startToFireTimeout" },
{ "type": "bad_decision_type",
"value": "FooBar",
"where": "decisions.1.member.decisionType",
"possible_values": "Foo, Bar, Baz"},
{"type": "null_value",
"where": "decisions.1.member.startTimerDecisionAttributes.startToFireTimeout"},
{"type": "bad_decision_type",
"value": "FooBar",
"where": "decisions.1.member.decisionType",
"possible_values": "Foo, Bar, Baz"},
])
ex.code.should.equal(400)
@ -137,10 +148,10 @@ def test_swf_decision_validation_error():
msg = ex.get_body()
msg.should.match(r"2 validation errors detected:")
msg.should.match(
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' "\
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.startToFireTimeout' "
r"failed to satisfy constraint: Member must not be null;"
)
msg.should.match(
r"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: " \
r"Value 'FooBar' at 'decisions.1.member.decisionType' failed to satisfy constraint: "
r"Member must satisfy enum value set: \[Foo, Bar, Baz\]"
)

View File

@ -15,9 +15,9 @@ from moto.swf.models import (
# intuitive behaviour in moto/swf own tests...
ACTIVITY_TASK_TIMEOUTS = {
"heartbeatTimeout": "300", # 5 mins
"scheduleToStartTimeout": "1800", # 30 mins
"scheduleToStartTimeout": "1800", # 30 mins
"startToCloseTimeout": "1800", # 30 mins
"scheduleToCloseTimeout": "2700", # 45 mins
"scheduleToCloseTimeout": "2700", # 45 mins
}
# Some useful decisions
@ -25,13 +25,14 @@ SCHEDULE_ACTIVITY_TASK_DECISION = {
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": { "name": "test-activity", "version": "v1.1" },
"taskList": { "name": "activity-task-list" },
"activityType": {"name": "test-activity", "version": "v1.1"},
"taskList": {"name": "activity-task-list"},
}
}
for key, value in ACTIVITY_TASK_TIMEOUTS.items():
SCHEDULE_ACTIVITY_TASK_DECISION["scheduleActivityTaskDecisionAttributes"][key] = value
# A test Domain
def get_basic_domain():
return Domain("test-domain", "90")
@ -48,10 +49,12 @@ def _generic_workflow_type_attributes():
"default_task_start_to_close_timeout": "300",
}
def get_basic_workflow_type():
args, kwargs = _generic_workflow_type_attributes()
return WorkflowType(*args, **kwargs)
def mock_basic_workflow_type(domain_name, conn):
args, kwargs = _generic_workflow_type_attributes()
conn.register_workflow_type(domain_name, *args, **kwargs)