Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

View file

@ -12,18 +12,19 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
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")
"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")
"test-domain", conn.run_id, "uid-abcd1234"
)
resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted")
resp["events"][-1]["activityTaskStartedEventAttributes"].should.equal(
{"identity": "surprise", "scheduledEventId": 5}
@ -48,14 +49,12 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
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})
@ -70,20 +69,22 @@ 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"]
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"]
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"
]
resp = conn.respond_activity_task_completed(
activity_token, result="result of the task")
activity_token, result="result of the task"
)
resp.should.be.none
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
"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}
@ -93,13 +94,13 @@ 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"]
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"]
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"
]
# bad: we're closing workflow execution manually, but endpoints are not
# coded for now..
@ -107,52 +108,57 @@ def test_respond_activity_task_completed_on_closed_workflow_execution():
wfe.execution_status = "CLOSED"
# /bad
conn.respond_activity_task_completed.when.called_with(
activity_token
).should.throw(SWFResponseError, "WorkflowExecution=")
conn.respond_activity_task_completed.when.called_with(activity_token).should.throw(
SWFResponseError, "WorkflowExecution="
)
@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"]
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"]
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"
]
conn.respond_activity_task_completed(activity_token)
conn.respond_activity_task_completed.when.called_with(
activity_token
).should.throw(SWFResponseError, "Unknown activity, scheduledEventId = 5")
conn.respond_activity_task_completed.when.called_with(activity_token).should.throw(
SWFResponseError, "Unknown activity, scheduledEventId = 5"
)
# RespondActivityTaskFailed endpoint
@mock_swf_deprecated
def test_respond_activity_task_failed():
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
])
activity_token = conn.poll_for_activity_task(
"test-domain", "activity-task-list")["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"
]
resp = conn.respond_activity_task_failed(activity_token,
reason="short reason",
details="long details")
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")
"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,
}
)
@ -162,11 +168,10 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
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_failed.when.called_with(
"not-a-correct-token"
@ -177,13 +182,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"]
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"]
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"
]
resp = conn.record_activity_task_heartbeat(activity_token)
resp.should.equal({"cancelRequested": False})
@ -192,13 +197,11 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
conn.poll_for_activity_task(
"test-domain", "activity-task-list")["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.record_activity_task_heartbeat.when.called_with(
"bad-token", details="some progress details"
@ -208,21 +211,23 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
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"]
"test-domain", "activity-task-list"
)["taskToken"]
conn.record_activity_task_heartbeat(
activity_token, details="some progress details")
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")
"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

@ -49,10 +49,11 @@ 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
@ -63,12 +64,14 @@ def test_list_activity_types_reverse_order():
conn.register_activity_type("test-domain", "a-test-activity", "v1.0")
conn.register_activity_type("test-domain", "c-test-activity", "v1.0")
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"])
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"])
# DeprecateActivityType endpoint
@ -112,11 +115,15 @@ def test_deprecate_non_existent_activity_type():
def test_describe_activity_type():
conn = boto.connect_swf("the_key", "the_secret")
conn.register_domain("test-domain", "60")
conn.register_activity_type("test-domain", "test-activity", "v1.0",
task_list="foo", default_task_heartbeat_timeout="32")
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

@ -14,18 +14,20 @@ def test_poll_for_decision_task_when_one():
conn = setup_workflow()
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
"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
@ -49,11 +51,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"])
["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]
)
# CountPendingDecisionTasks endpoint
@ -91,29 +93,32 @@ def test_respond_decision_task_completed_with_no_decision():
task_token = resp["taskToken"]
resp = conn.respond_decision_task_completed(
task_token,
execution_context="free-form context",
task_token, execution_context="free-form context"
)
resp.should.be.none
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
"test-domain", conn.run_id, "uid-abcd1234"
)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
])
types.should.equal(
[
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
]
)
evt = resp["events"][-1]
evt["decisionTaskCompletedEventAttributes"].should.equal({
"executionContext": "free-form context",
"scheduledEventId": 2,
"startedEventId": 3,
})
evt["decisionTaskCompletedEventAttributes"].should.equal(
{
"executionContext": "free-form context",
"scheduledEventId": 2,
"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")
@ -138,9 +143,9 @@ def test_respond_decision_task_completed_on_close_workflow_execution():
wfe.execution_status = "CLOSED"
# /bad
conn.respond_decision_task_completed.when.called_with(
task_token
).should.throw(SWFResponseError)
conn.respond_decision_task_completed.when.called_with(task_token).should.throw(
SWFResponseError
)
@mock_swf_deprecated
@ -150,9 +155,9 @@ def test_respond_decision_task_completed_with_task_already_completed():
task_token = resp["taskToken"]
conn.respond_decision_task_completed(task_token)
conn.respond_decision_task_completed.when.called_with(
task_token
).should.throw(SWFResponseError)
conn.respond_decision_task_completed.when.called_with(task_token).should.throw(
SWFResponseError
)
@mock_swf_deprecated
@ -161,26 +166,31 @@ def test_respond_decision_task_completed_with_complete_workflow_execution():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
decisions = [{
"decisionType": "CompleteWorkflowExecution",
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"}
}]
resp = conn.respond_decision_task_completed(
task_token, decisions=decisions)
decisions = [
{
"decisionType": "CompleteWorkflowExecution",
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"},
}
]
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")
"test-domain", conn.run_id, "uid-abcd1234"
)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"WorkflowExecutionCompleted",
])
types.should.equal(
[
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"WorkflowExecutionCompleted",
]
)
resp["events"][-1]["workflowExecutionCompletedEventAttributes"][
"result"].should.equal("foo bar")
"result"
].should.equal("foo bar")
@mock_swf_deprecated
@ -211,9 +221,10 @@ def test_respond_decision_task_completed_with_invalid_decision_type():
]
conn.respond_decision_task_completed.when.called_with(
task_token, decisions=decisions).should.throw(
SWFResponseError,
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'"
task_token, decisions=decisions
).should.throw(
SWFResponseError,
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'",
)
@ -226,8 +237,8 @@ def test_respond_decision_task_completed_with_missing_attributes():
decisions = [
{
"decisionType": "should trigger even with incorrect decision type",
"startTimerDecisionAttributes": {}
},
"startTimerDecisionAttributes": {},
}
]
conn.respond_decision_task_completed.when.called_with(
@ -235,7 +246,7 @@ def test_respond_decision_task_completed_with_missing_attributes():
).should.throw(
SWFResponseError,
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
r"failed to satisfy constraint: Member must not be null"
r"failed to satisfy constraint: Member must not be null",
)
@ -245,16 +256,14 @@ def test_respond_decision_task_completed_with_missing_attributes_totally():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
decisions = [
{"decisionType": "StartTimer"},
]
decisions = [{"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"
r"failed to satisfy constraint: Member must not be null",
)
@ -264,24 +273,31 @@ def test_respond_decision_task_completed_with_fail_workflow_execution():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
decisions = [{
"decisionType": "FailWorkflowExecution",
"failWorkflowExecutionDecisionAttributes": {"reason": "my rules", "details": "foo"}
}]
resp = conn.respond_decision_task_completed(
task_token, decisions=decisions)
decisions = [
{
"decisionType": "FailWorkflowExecution",
"failWorkflowExecutionDecisionAttributes": {
"reason": "my rules",
"details": "foo",
},
}
]
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")
"test-domain", conn.run_id, "uid-abcd1234"
)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"WorkflowExecutionFailed",
])
types.should.equal(
[
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"WorkflowExecutionFailed",
]
)
attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"]
attrs["reason"].should.equal("my rules")
attrs["details"].should.equal("foo")
@ -294,49 +310,44 @@ def test_respond_decision_task_completed_with_schedule_activity_task():
resp = conn.poll_for_decision_task("test-domain", "queue")
task_token = resp["taskToken"]
decisions = [{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity",
"version": "v1.1"
},
"heartbeatTimeout": "60",
"input": "123",
"taskList": {
"name": "my-task-list"
decisions = [
{
"decisionType": "ScheduleActivityTask",
"scheduleActivityTaskDecisionAttributes": {
"activityId": "my-activity-001",
"activityType": {"name": "test-activity", "version": "v1.1"},
"heartbeatTimeout": "60",
"input": "123",
"taskList": {"name": "my-task-list"},
},
}
}]
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")
"test-domain", conn.run_id, "uid-abcd1234"
)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal([
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"ActivityTaskScheduled",
])
resp["events"][-1]["activityTaskScheduledEventAttributes"].should.equal({
"decisionTaskCompletedEventId": 4,
"activityId": "my-activity-001",
"activityType": {
"name": "test-activity",
"version": "v1.1",
},
"heartbeatTimeout": "60",
"input": "123",
"taskList": {
"name": "my-task-list"
},
})
types.should.equal(
[
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskCompleted",
"ActivityTaskScheduled",
]
)
resp["events"][-1]["activityTaskScheduledEventAttributes"].should.equal(
{
"decisionTaskCompletedEventId": 4,
"activityId": "my-activity-001",
"activityType": {"name": "test-activity", "version": "v1.1"},
"heartbeatTimeout": "60",
"input": "123",
"taskList": {"name": "my-task-list"},
}
)
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

@ -82,18 +82,16 @@ def test_deprecate_already_deprecated_domain():
conn.register_domain("test-domain", "60", description="A test domain")
conn.deprecate_domain("test-domain")
conn.deprecate_domain.when.called_with(
"test-domain"
).should.throw(SWFResponseError)
conn.deprecate_domain.when.called_with("test-domain").should.throw(SWFResponseError)
@mock_swf_deprecated
def test_deprecate_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")
conn.deprecate_domain.when.called_with(
"non-existent"
).should.throw(SWFResponseError)
conn.deprecate_domain.when.called_with("non-existent").should.throw(
SWFResponseError
)
# DescribeDomain endpoint
@ -103,8 +101,7 @@ 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")
@ -114,6 +111,4 @@ def test_describe_domain():
def test_describe_non_existent_domain():
conn = boto.connect_swf("the_key", "the_secret")
conn.describe_domain.when.called_with(
"non-existent"
).should.throw(SWFResponseError)
conn.describe_domain.when.called_with("non-existent").should.throw(SWFResponseError)

View file

@ -12,23 +12,27 @@ 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"]
conn.respond_decision_task_completed(decision_token, decisions=[
SCHEDULE_ACTIVITY_TASK_DECISION
])
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")
"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")
"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")
"test-domain", conn.run_id, "uid-abcd1234"
)
resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut")
attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]
@ -50,7 +54,8 @@ def test_decision_task_start_to_close_timeout():
with freeze_time("2015-01-01 12:04:30"):
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
"test-domain", conn.run_id, "uid-abcd1234"
)
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
@ -60,17 +65,27 @@ 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")
"test-domain", conn.run_id, "uid-abcd1234"
)
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted",
"DecisionTaskTimedOut", "DecisionTaskScheduled"]
[
"WorkflowExecutionStarted",
"DecisionTaskScheduled",
"DecisionTaskStarted",
"DecisionTaskTimedOut",
"DecisionTaskScheduled",
]
)
attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"]
attrs.should.equal({
"scheduledEventId": 2, "startedEventId": 3, "timeoutType": "START_TO_CLOSE"
})
attrs.should.equal(
{
"scheduledEventId": 2,
"startedEventId": 3,
"timeoutType": "START_TO_CLOSE",
}
)
# checks that event has been emitted at 12:05:00, not 12:05:30
resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0)
@ -85,26 +100,27 @@ def test_workflow_execution_start_to_close_timeout():
with freeze_time("2015-01-01 13:59:30"):
resp = conn.get_workflow_execution_history(
"test-domain", conn.run_id, "uid-abcd1234")
"test-domain", conn.run_id, "uid-abcd1234"
)
event_types = [evt["eventType"] for evt in resp["events"]]
event_types.should.equal(
["WorkflowExecutionStarted", "DecisionTaskScheduled"]
)
event_types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
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")
"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({
"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"
})
attrs.should.equal({"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"})
# checks that event has been emitted at 14:00:00, not 14:00:30
resp["events"][-1]["eventTimestamp"].should.equal(1420120800.0)

View file

@ -3,6 +3,7 @@ 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
@ -16,8 +17,11 @@ def setup_swf_environment():
conn = boto.connect_swf("the_key", "the_secret")
conn.register_domain("test-domain", "60", description="A test domain")
conn.register_workflow_type(
"test-domain", "test-workflow", "v1.0",
task_list="queue", default_child_policy="TERMINATE",
"test-domain",
"test-workflow",
"v1.0",
task_list="queue",
default_child_policy="TERMINATE",
default_execution_start_to_close_timeout="300",
default_task_start_to_close_timeout="300",
)
@ -31,29 +35,34 @@ def test_start_workflow_execution():
conn = setup_swf_environment()
wf = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
)
wf.should.contain("runId")
@mock_swf_deprecated
def test_signal_workflow_execution():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
)
run_id = hsh["runId"]
wfe = conn.signal_workflow_execution(
"test-domain", "my_signal", "uid-abcd1234", "my_input", run_id)
"test-domain", "my_signal", "uid-abcd1234", "my_input", run_id
)
wfe = conn.describe_workflow_execution(
"test-domain", run_id, "uid-abcd1234")
wfe = conn.describe_workflow_execution("test-domain", run_id, "uid-abcd1234")
wfe["openCounts"]["openDecisionTasks"].should.equal(2)
@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")
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
)
conn.start_workflow_execution.when.called_with(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
@ -75,13 +84,12 @@ def test_start_workflow_execution_on_deprecated_type():
def test_describe_workflow_execution():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
"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")
@ -99,11 +107,11 @@ def test_describe_non_existent_workflow_execution():
def test_get_workflow_execution_history():
conn = setup_swf_environment()
hsh = conn.start_workflow_execution(
"test-domain", "uid-abcd1234", "test-workflow", "v1.0")
"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"])
@ -112,11 +120,13 @@ def test_get_workflow_execution_history():
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")
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
)
run_id = hsh["runId"]
resp = conn.get_workflow_execution_history("test-domain", run_id, "uid-abcd1234",
reverse_order=True)
resp = conn.get_workflow_execution_history(
"test-domain", run_id, "uid-abcd1234", reverse_order=True
)
types = [evt["eventType"] for evt in resp["events"]]
types.should.equal(["DecisionTaskScheduled", "WorkflowExecutionStarted"])
@ -136,32 +146,36 @@ 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'
"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)
"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.utcnow() - 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']
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')
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
@ -170,33 +184,36 @@ 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'
"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)
"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.utcnow() - 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']
"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')
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
@ -207,14 +224,16 @@ def test_terminate_workflow_execution():
"test-domain", "uid-abcd1234", "test-workflow", "v1.0"
)["runId"]
resp = conn.terminate_workflow_execution("test-domain", "uid-abcd1234",
details="some details",
reason="a more complete reason",
run_id=run_id)
resp = conn.terminate_workflow_execution(
"test-domain",
"uid-abcd1234",
details="some details",
reason="a more complete reason",
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"]
@ -243,16 +262,12 @@ def test_terminate_workflow_execution_with_wrong_workflow_or_run_id():
# already closed, without run_id
conn.terminate_workflow_execution.when.called_with(
"test-domain", "uid-abcd1234"
).should.throw(
SWFResponseError, "Unknown execution, workflowId = uid-abcd1234"
)
).should.throw(SWFResponseError, "Unknown execution, workflowId = uid-abcd1234")
# wrong workflow id
conn.terminate_workflow_execution.when.called_with(
"test-domain", "uid-non-existent"
).should.throw(
SWFResponseError, "Unknown execution, workflowId = uid-non-existent"
)
).should.throw(SWFResponseError, "Unknown execution, workflowId = uid-non-existent")
# wrong run_id
conn.terminate_workflow_execution.when.called_with(

View file

@ -49,10 +49,11 @@ 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,12 +64,14 @@ def test_list_workflow_types_reverse_order():
conn.register_workflow_type("test-domain", "a-test-workflow", "v1.0")
conn.register_workflow_type("test-domain", "c-test-workflow", "v1.0")
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"])
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"])
# DeprecateWorkflowType endpoint
@ -112,15 +115,18 @@ def test_deprecate_non_existent_workflow_type():
def test_describe_workflow_type():
conn = boto.connect_swf("the_key", "the_secret")
conn.register_domain("test-domain", "60")
conn.register_workflow_type("test-domain", "test-workflow", "v1.0",
task_list="foo", default_child_policy="TERMINATE")
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")