This commit is contained in:
Steve Pulec 2017-02-23 21:37:43 -05:00
commit f37bad0e00
260 changed files with 6363 additions and 3766 deletions

View file

@ -147,6 +147,7 @@ def test_activity_task_cannot_change_state_on_closed_workflow_execution():
)
wfe.complete(123)
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(SWFWorkflowExecutionClosedError)
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(
SWFWorkflowExecutionClosedError)
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
task.fail.when.called_with().should.throw(SWFWorkflowExecutionClosedError)

View file

@ -75,5 +75,6 @@ def test_decision_task_cannot_change_state_on_closed_workflow_execution():
wfe.complete(123)
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(SWFWorkflowExecutionClosedError)
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(
SWFWorkflowExecutionClosedError)
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)

View file

@ -15,7 +15,8 @@ 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")
@ -67,16 +68,23 @@ def test_domain_decision_tasks():
def test_domain_get_workflow_execution():
domain = Domain("my-domain", "60")
wfe1 = WorkflowExecution(workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True)
wfe2 = WorkflowExecution(workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False)
wfe3 = WorkflowExecution(workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True)
wfe4 = WorkflowExecution(workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False)
wfe1 = WorkflowExecution(
workflow_id="wf-id-1", run_id="run-id-1", execution_status="OPEN", open=True)
wfe2 = WorkflowExecution(
workflow_id="wf-id-1", run_id="run-id-2", execution_status="CLOSED", open=False)
wfe3 = WorkflowExecution(
workflow_id="wf-id-2", run_id="run-id-3", execution_status="OPEN", open=True)
wfe4 = WorkflowExecution(
workflow_id="wf-id-3", run_id="run-id-4", execution_status="CLOSED", open=False)
domain.workflow_executions = [wfe1, wfe2, wfe3, wfe4]
# get workflow execution through workflow_id and run_id
domain.get_workflow_execution("wf-id-1", run_id="run-id-1").should.equal(wfe1)
domain.get_workflow_execution("wf-id-1", run_id="run-id-2").should.equal(wfe2)
domain.get_workflow_execution("wf-id-3", run_id="run-id-4").should.equal(wfe4)
domain.get_workflow_execution(
"wf-id-1", run_id="run-id-1").should.equal(wfe1)
domain.get_workflow_execution(
"wf-id-1", run_id="run-id-2").should.equal(wfe2)
domain.get_workflow_execution(
"wf-id-3", run_id="run-id-4").should.equal(wfe4)
domain.get_workflow_execution.when.called_with(
"wf-id-1", run_id="non-existent"
@ -98,7 +106,8 @@ def test_domain_get_workflow_execution():
)
# raise_if_closed attribute
domain.get_workflow_execution("wf-id-1", run_id="run-id-1", raise_if_closed=True).should.equal(wfe1)
domain.get_workflow_execution(
"wf-id-1", run_id="run-id-1", raise_if_closed=True).should.equal(wfe1)
domain.get_workflow_execution.when.called_with(
"wf-id-3", run_id="run-id-4", raise_if_closed=True
).should.throw(

View file

@ -3,6 +3,7 @@ from moto.swf.models import GenericType
# Tests for GenericType (ActivityType, WorkflowType)
class FooType(GenericType):
@property
def kind(self):
return "foo"
@ -38,10 +39,12 @@ def test_type_full_dict_representation():
_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")
_type.to_full_dict()["configuration"][
"justAnExampleTimeout"].should.equal("60")
_type.non_whitelisted_property = "34"
keys = _type.to_full_dict()["configuration"].keys()
@ -50,4 +53,5 @@ def test_type_full_dict_representation():
def test_type_string_representation():
_type = FooType("test-foo", "v1.0")
str(_type).should.equal("FooType(name: test-foo, version: v1.0, status: REGISTERED)")
str(_type).should.equal(
"FooType(name: test-foo, version: v1.0, status: REGISTERED)")

View file

@ -240,8 +240,10 @@ def test_workflow_execution_schedule_activity_task():
wfe.open_counts["openActivityTasks"].should.equal(1)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ActivityTaskScheduled")
last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123)
last_event.event_attributes["taskList"]["name"].should.equal("task-list-name")
last_event.event_attributes[
"decisionTaskCompletedEventId"].should.equal(123)
last_event.event_attributes["taskList"][
"name"].should.equal("task-list-name")
wfe.activity_tasks.should.have.length_of(1)
task = wfe.activity_tasks[0]
@ -288,43 +290,50 @@ def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attribut
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DOES_NOT_EXIST")
last_event.event_attributes["cause"].should.equal(
"ACTIVITY_TYPE_DOES_NOT_EXIST")
hsh["activityType"]["name"] = "test-activity"
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DEPRECATED")
last_event.event_attributes["cause"].should.equal(
"ACTIVITY_TYPE_DEPRECATED")
hsh["activityType"]["version"] = "v1.2"
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_TASK_LIST_UNDEFINED")
last_event.event_attributes["cause"].should.equal(
"DEFAULT_TASK_LIST_UNDEFINED")
hsh["taskList"] = {"name": "foobar"}
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_SCHEDULE_TO_START_TIMEOUT_UNDEFINED")
last_event.event_attributes["cause"].should.equal(
"DEFAULT_SCHEDULE_TO_START_TIMEOUT_UNDEFINED")
hsh["scheduleToStartTimeout"] = "600"
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_SCHEDULE_TO_CLOSE_TIMEOUT_UNDEFINED")
last_event.event_attributes["cause"].should.equal(
"DEFAULT_SCHEDULE_TO_CLOSE_TIMEOUT_UNDEFINED")
hsh["scheduleToCloseTimeout"] = "600"
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_START_TO_CLOSE_TIMEOUT_UNDEFINED")
last_event.event_attributes["cause"].should.equal(
"DEFAULT_START_TO_CLOSE_TIMEOUT_UNDEFINED")
hsh["startToCloseTimeout"] = "600"
wfe.schedule_activity_task(123, hsh)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("DEFAULT_HEARTBEAT_TIMEOUT_UNDEFINED")
last_event.event_attributes["cause"].should.equal(
"DEFAULT_HEARTBEAT_TIMEOUT_UNDEFINED")
wfe.open_counts["openActivityTasks"].should.equal(0)
wfe.activity_tasks.should.have.length_of(0)
@ -393,7 +402,8 @@ def test_workflow_execution_schedule_activity_task_with_same_activity_id():
wfe.open_counts["openActivityTasks"].should.equal(1)
last_event = wfe.events()[-1]
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
last_event.event_attributes["cause"].should.equal("ACTIVITY_ID_ALREADY_IN_USE")
last_event.event_attributes["cause"].should.equal(
"ACTIVITY_ID_ALREADY_IN_USE")
def test_workflow_execution_start_activity_task():
@ -456,7 +466,8 @@ def test_first_timeout():
wfe.first_timeout().should.be.a(Timeout)
# See moto/swf/models/workflow_execution.py "_process_timeouts()" for more details
# 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:
# - execution start to close timeout of 8 mins

View file

@ -11,15 +11,18 @@ from ..utils import setup_workflow, SCHEDULE_ACTIVITY_TASK_DECISION
@mock_swf_deprecated
def test_poll_for_activity_task_when_one():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
resp = conn.poll_for_activity_task("test-domain", "activity-task-list", identity="surprise")
resp = conn.poll_for_activity_task(
"test-domain", "activity-task-list", identity="surprise")
resp["activityId"].should.equal("my-activity-001")
resp["taskToken"].should_not.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
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}
@ -44,12 +47,14 @@ def test_poll_for_activity_task_on_non_existent_queue():
@mock_swf_deprecated
def test_count_pending_activity_tasks():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
resp = conn.count_pending_activity_tasks("test-domain", "activity-task-list")
resp = conn.count_pending_activity_tasks(
"test-domain", "activity-task-list")
resp.should.equal({"count": 1, "truncated": False})
@ -64,16 +69,20 @@ def test_count_pending_decision_tasks_on_non_existent_task_list():
@mock_swf_deprecated
def test_respond_activity_task_completed():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
resp = conn.respond_activity_task_completed(activity_token, result="result of the task")
resp = conn.respond_activity_task_completed(
activity_token, result="result of the task")
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
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}
@ -83,13 +92,16 @@ def test_respond_activity_task_completed():
@mock_swf_deprecated
def test_respond_activity_task_completed_on_closed_workflow_execution():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
# bad: we're closing workflow execution manually, but endpoints are not coded for now..
# bad: we're closing workflow execution manually, but endpoints are not
# coded for now..
wfe = swf_backend.domains[0].workflow_executions[-1]
wfe.execution_status = "CLOSED"
# /bad
@ -102,11 +114,13 @@ def test_respond_activity_task_completed_on_closed_workflow_execution():
@mock_swf_deprecated
def test_respond_activity_task_completed_with_task_already_completed():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
conn.respond_activity_task_completed(activity_token)
@ -119,18 +133,21 @@ def test_respond_activity_task_completed_with_task_already_completed():
@mock_swf_deprecated
def test_respond_activity_task_failed():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
resp = conn.respond_activity_task_failed(activity_token,
reason="short reason",
details="long details")
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
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",
@ -144,7 +161,8 @@ def test_respond_activity_task_completed_with_wrong_token():
# because the safeguards are shared with RespondActivityTaskCompleted, so
# no need to retest everything end-to-end.
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
@ -158,11 +176,13 @@ def test_respond_activity_task_completed_with_wrong_token():
@mock_swf_deprecated
def test_record_activity_task_heartbeat():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
resp = conn.record_activity_task_heartbeat(activity_token)
resp.should.equal({"cancelRequested": False})
@ -171,11 +191,13 @@ def test_record_activity_task_heartbeat():
@mock_swf_deprecated
def test_record_activity_task_heartbeat_with_wrong_token():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
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")["taskToken"]
conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
conn.record_activity_task_heartbeat.when.called_with(
"bad-token", details="some progress details"
@ -185,17 +207,21 @@ def test_record_activity_task_heartbeat_with_wrong_token():
@mock_swf_deprecated
def test_record_activity_task_heartbeat_sets_details_in_case_of_timeout():
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
decision_token = conn.poll_for_decision_task(
"test-domain", "queue")["taskToken"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
with freeze_time("2015-01-01 12:00:00"):
activity_token = conn.poll_for_activity_task("test-domain", "activity-task-list")["taskToken"]
conn.record_activity_task_heartbeat(activity_token, details="some progress details")
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["taskToken"]
conn.record_activity_task_heartbeat(
activity_token, details="some progress details")
with freeze_time("2015-01-01 12:05:30"):
# => Activity Task Heartbeat timeout reached!!
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut")
attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]
attrs["details"].should.equal("some progress details")

View file

@ -48,8 +48,10 @@ def test_list_activity_types():
conn.register_activity_type("test-domain", "c-test-activity", "v1.0")
all_activity_types = conn.list_activity_types("test-domain", "REGISTERED")
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"])
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_deprecated
@ -62,8 +64,10 @@ def test_list_activity_types_reverse_order():
all_activity_types = conn.list_activity_types("test-domain", "REGISTERED",
reverse_order=True)
names = [activity_type["activityType"]["name"] for activity_type in all_activity_types["typeInfos"]]
names.should.equal(["c-test-activity", "b-test-activity", "a-test-activity"])
names = [activity_type["activityType"]["name"]
for activity_type in all_activity_types["typeInfos"]]
names.should.equal(
["c-test-activity", "b-test-activity", "a-test-activity"])
# DeprecateActivityType endpoint
@ -110,7 +114,8 @@ def test_describe_activity_type():
conn.register_activity_type("test-domain", "test-activity", "v1.0",
task_list="foo", default_task_heartbeat_timeout="32")
actype = conn.describe_activity_type("test-domain", "test-activity", "v1.0")
actype = conn.describe_activity_type(
"test-domain", "test-activity", "v1.0")
actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
infos = actype["typeInfo"]
infos["activityType"]["name"].should.equal("test-activity")

View file

@ -12,15 +12,19 @@ from ..utils import setup_workflow
def test_poll_for_decision_task_when_one():
conn = setup_workflow()
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
resp = conn.poll_for_decision_task("test-domain", "queue", identity="srv01")
resp = conn.poll_for_decision_task(
"test-domain", "queue", identity="srv01")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"])
types.should.equal(["WorkflowExecutionStarted",
"DecisionTaskScheduled", "DecisionTaskStarted"])
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01")
resp[
"events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01")
@mock_swf_deprecated
@ -44,9 +48,11 @@ def test_poll_for_decision_task_on_non_existent_queue():
@mock_swf_deprecated
def test_poll_for_decision_task_with_reverse_order():
conn = setup_workflow()
resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True)
resp = conn.poll_for_decision_task(
"test-domain", "queue", reverse_order=True)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"])
types.should.equal(
["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"])
# CountPendingDecisionTasks endpoint
@ -89,7 +95,8 @@ def test_respond_decision_task_completed_with_no_decision():
)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
@ -104,7 +111,8 @@ def test_respond_decision_task_completed_with_no_decision():
"startedEventId": 3,
})
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.describe_workflow_execution(
"test-domain", conn.run_id, "uid-abcd1234")
resp["latestExecutionContext"].should.equal("free-form context")
@ -123,7 +131,8 @@ def test_respond_decision_task_completed_on_close_workflow_execution():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
# bad: we're closing workflow execution manually, but endpoints are not coded for now..
# bad: we're closing workflow execution manually, but endpoints are not
# coded for now..
wfe = swf_backend.domains[0].workflow_executions[-1]
wfe.execution_status = "CLOSED"
# /bad
@ -155,10 +164,12 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
"decisionType": "CompleteWorkflowExecution",
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"}
}]
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
resp = conn.respond_decision_task_completed(
task_token, decisions=decisions)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
@ -167,7 +178,8 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
"DecisionTaskCompleted",
"WorkflowExecutionCompleted",
])
resp["events"][-1]["workflowExecutionCompletedEventAttributes"]["result"].should.equal("foo bar")
resp["events"][-1]["workflowExecutionCompletedEventAttributes"][
"result"].should.equal("foo bar")
@mock_swf_deprecated
@ -255,10 +267,12 @@ def test_respond_decision_task_completed_with_fail_workflow_execution():
"decisionType": "FailWorkflowExecution",
"failWorkflowExecutionDecisionAttributes": {"reason": "my rules", "details": "foo"}
}]
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
resp = conn.respond_decision_task_completed(
task_token, decisions=decisions)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
@ -294,10 +308,12 @@ def test_respond_decision_task_completed_with_schedule_activity_task():
},
}
}]
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
resp = conn.respond_decision_task_completed(
task_token, decisions=decisions)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
@ -320,5 +336,6 @@ def test_respond_decision_task_completed_with_schedule_activity_task():
},
})
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.describe_workflow_execution(
"test-domain", conn.run_id, "uid-abcd1234")
resp["latestActivityTaskTimestamp"].should.equal(1420113600.0)

View file

@ -102,7 +102,8 @@ def test_describe_domain():
conn.register_domain("test-domain", "60", description="A test domain")
domain = conn.describe_domain("test-domain")
domain["configuration"]["workflowExecutionRetentionPeriodInDays"].should.equal("60")
domain["configuration"][
"workflowExecutionRetentionPeriodInDays"].should.equal("60")
domain["domainInfo"]["description"].should.equal("A test domain")
domain["domainInfo"]["name"].should.equal("test-domain")
domain["domainInfo"]["status"].should.equal("REGISTERED")

View file

@ -11,19 +11,23 @@ from ..utils import setup_workflow, SCHEDULE_ACTIVITY_TASK_DECISION
def test_activity_task_heartbeat_timeout():
with freeze_time("2015-01-01 12:00:00"):
conn = setup_workflow()
decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
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", identity="surprise")
conn.poll_for_activity_task(
"test-domain", "activity-task-list", identity="surprise")
with freeze_time("2015-01-01 12:04:30"):
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted")
with freeze_time("2015-01-01 12:05:30"):
# => Activity Task Heartbeat timeout reached!!
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut")
attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]
@ -44,7 +48,8 @@ def test_decision_task_start_to_close_timeout():
conn.poll_for_decision_task("test-domain", "queue")["taskToken"]
with freeze_time("2015-01-01 12:04:30"):
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
@ -53,7 +58,8 @@ def test_decision_task_start_to_close_timeout():
with freeze_time("2015-01-01 12:05:30"):
# => Decision Task Start to Close timeout reached!!
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
@ -77,7 +83,8 @@ def test_workflow_execution_start_to_close_timeout():
conn = setup_workflow()
with freeze_time("2015-01-01 13:59:30"):
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
@ -86,11 +93,13 @@ def test_workflow_execution_start_to_close_timeout():
with freeze_time("2015-01-01 14:00:30"):
# => Workflow Execution Start to Close timeout reached!!
resp = conn.get_workflow_execution_history("test-domain", conn.run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
["WorkflowExecutionStarted", "DecisionTaskScheduled", "WorkflowExecutionTimedOut"]
["WorkflowExecutionStarted", "DecisionTaskScheduled",
"WorkflowExecutionTimedOut"]
)
attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"]
attrs.should.equal({

View file

@ -30,14 +30,16 @@ def setup_swf_environment():
def test_start_workflow_execution():
conn = setup_swf_environment()
wf = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
wf = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
wf.should.contain("runId")
@mock_swf_deprecated
def test_start_already_started_workflow_execution():
conn = setup_swf_environment()
conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
conn.start_workflow_execution.when.called_with(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
@ -58,11 +60,14 @@ def test_start_workflow_execution_on_deprecated_type():
@mock_swf_deprecated
def test_describe_workflow_execution():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
run_id = hsh["runId"]
wfe = conn.describe_workflow_execution("test-domain", run_id, "uid-abcd1234")
wfe["executionInfo"]["execution"]["workflowId"].should.equal("uid-abcd1234")
wfe = conn.describe_workflow_execution(
"test-domain", run_id, "uid-abcd1234")
wfe["executionInfo"]["execution"][
"workflowId"].should.equal("uid-abcd1234")
wfe["executionInfo"]["executionStatus"].should.equal("OPEN")
@ -79,10 +84,12 @@ def test_describe_non_existent_workflow_execution():
@mock_swf_deprecated
def test_get_workflow_execution_history():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
run_id = hsh["runId"]
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", run_id, "uid-abcd1234")
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
@ -90,7 +97,8 @@ def test_get_workflow_execution_history():
@mock_swf_deprecated
def test_get_workflow_execution_history_with_reverse_order():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
run_id = hsh["runId"]
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234",
@ -191,7 +199,8 @@ def test_terminate_workflow_execution():
run_id=run_id)
resp.should.be.none
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234")
resp = conn.get_workflow_execution_history(
"test-domain", run_id, "uid-abcd1234")
evt = resp["events"][-1]
evt["eventType"].should.equal("WorkflowExecutionTerminated")
attrs = evt["workflowExecutionTerminatedEventAttributes"]

View file

@ -49,8 +49,10 @@ def test_list_workflow_types():
conn.register_workflow_type("test-domain", "c-test-workflow", "v1.0")
all_workflow_types = conn.list_workflow_types("test-domain", "REGISTERED")
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"])
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_deprecated
@ -63,8 +65,10 @@ def test_list_workflow_types_reverse_order():
all_workflow_types = conn.list_workflow_types("test-domain", "REGISTERED",
reverse_order=True)
names = [activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"]]
names.should.equal(["c-test-workflow", "b-test-workflow", "a-test-workflow"])
names = [activity_type["workflowType"]["name"]
for activity_type in all_workflow_types["typeInfos"]]
names.should.equal(
["c-test-workflow", "b-test-workflow", "a-test-workflow"])
# DeprecateWorkflowType endpoint
@ -111,10 +115,12 @@ def test_describe_workflow_type():
conn.register_workflow_type("test-domain", "test-workflow", "v1.0",
task_list="foo", default_child_policy="TERMINATE")
actype = conn.describe_workflow_type("test-domain", "test-workflow", "v1.0")
actype = conn.describe_workflow_type(
"test-domain", "test-workflow", "v1.0")
actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
actype["configuration"]["defaultChildPolicy"].should.equal("TERMINATE")
actype["configuration"].keys().should_not.contain("defaultTaskStartToCloseTimeout")
actype["configuration"].keys().should_not.contain(
"defaultTaskStartToCloseTimeout")
infos = actype["typeInfo"]
infos["workflowType"]["name"].should.equal("test-workflow")
infos["workflowType"]["version"].should.equal("v1.0")

View file

@ -29,7 +29,8 @@ SCHEDULE_ACTIVITY_TASK_DECISION = {
}
}
for key, value in ACTIVITY_TASK_TIMEOUTS.items():
SCHEDULE_ACTIVITY_TASK_DECISION["scheduleActivityTaskDecisionAttributes"][key] = value
SCHEDULE_ACTIVITY_TASK_DECISION[
"scheduleActivityTaskDecisionAttributes"][key] = value
# A test Domain
@ -86,7 +87,8 @@ def setup_workflow():
default_task_schedule_to_start_timeout="600",
default_task_start_to_close_timeout="600",
)
wfe = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
wfe = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
conn.run_id = wfe["runId"]
return conn