2016-01-17 23:00:57 +00:00
|
|
|
from boto.swf.exceptions import SWFResponseError
|
2021-09-21 22:00:20 +00:00
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
from datetime import datetime
|
2015-10-31 20:13:44 +00:00
|
|
|
from freezegun import freeze_time
|
2021-10-18 19:44:29 +00:00
|
|
|
import sure # noqa # pylint: disable=unused-import
|
2021-09-21 22:00:20 +00:00
|
|
|
import pytest
|
2015-10-11 12:02:55 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
from moto import mock_swf_deprecated, mock_swf, settings
|
2015-10-12 09:08:52 +00:00
|
|
|
from moto.swf import swf_backend
|
2015-10-11 12:02:55 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
from ..utils import setup_workflow, setup_workflow_boto3
|
2015-10-11 12:02:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
# PollForDecisionTask endpoint
|
2021-09-21 22:00:20 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 12:02:55 +00:00
|
|
|
def test_poll_for_decision_task_when_one():
|
|
|
|
conn = setup_workflow()
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
resp = conn.get_workflow_execution_history(
|
2019-10-31 15:44:26 +00:00
|
|
|
"test-domain", conn.run_id, "uid-abcd1234"
|
|
|
|
)
|
2015-10-11 12:02:55 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue", identity="srv01")
|
2015-10-11 12:02:55 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2019-10-31 15:44:26 +00:00
|
|
|
types.should.equal(
|
|
|
|
["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"]
|
|
|
|
)
|
2015-10-11 12:02:55 +00:00
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal(
|
|
|
|
"srv01"
|
|
|
|
)
|
2015-10-11 12:02:55 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_poll_for_decision_task_when_one_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"])
|
|
|
|
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}, identity="srv01"
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(
|
|
|
|
["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"]
|
|
|
|
)
|
|
|
|
|
|
|
|
resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal(
|
|
|
|
"srv01"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2020-02-25 15:08:03 +00:00
|
|
|
@mock_swf_deprecated
|
|
|
|
def test_poll_for_decision_task_previous_started_event_id():
|
|
|
|
conn = setup_workflow()
|
|
|
|
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
assert resp["workflowExecution"]["runId"] == conn.run_id
|
|
|
|
assert "previousStartedEventId" not in resp
|
|
|
|
|
|
|
|
# Require a failing decision, in this case a non-existant activity type
|
|
|
|
attrs = {
|
|
|
|
"activityId": "spam",
|
|
|
|
"activityType": {"name": "test-activity", "version": "v1.42"},
|
|
|
|
"taskList": "eggs",
|
|
|
|
}
|
|
|
|
decision = {
|
|
|
|
"decisionType": "ScheduleActivityTask",
|
|
|
|
"scheduleActivityTaskDecisionAttributes": attrs,
|
|
|
|
}
|
|
|
|
conn.respond_decision_task_completed(resp["taskToken"], decisions=[decision])
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
assert resp["workflowExecution"]["runId"] == conn.run_id
|
|
|
|
assert resp["previousStartedEventId"] == 3
|
|
|
|
|
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_poll_for_decision_task_previous_started_event_id_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
assert resp["workflowExecution"]["runId"] == client.run_id
|
|
|
|
assert "previousStartedEventId" not in resp
|
|
|
|
|
|
|
|
# Require a failing decision, in this case a non-existant activity type
|
|
|
|
attrs = {
|
|
|
|
"activityId": "spam",
|
|
|
|
"activityType": {"name": "test-activity", "version": "v1.42"},
|
|
|
|
"taskList": {"name": "eggs"},
|
|
|
|
}
|
|
|
|
decision = {
|
|
|
|
"decisionType": "ScheduleActivityTask",
|
|
|
|
"scheduleActivityTaskDecisionAttributes": attrs,
|
|
|
|
}
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=resp["taskToken"], decisions=[decision]
|
|
|
|
)
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
assert resp["workflowExecution"]["runId"] == client.run_id
|
|
|
|
assert resp["previousStartedEventId"] == 3
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 12:02:55 +00:00
|
|
|
def test_poll_for_decision_task_when_none():
|
|
|
|
conn = setup_workflow()
|
|
|
|
conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
# this is the DecisionTask representation you get from the real SWF
|
|
|
|
# after waiting 60s when there's no decision to be taken
|
2021-02-12 13:01:42 +00:00
|
|
|
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
|
2015-10-11 17:14:31 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_poll_for_decision_task_when_none_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
|
|
|
|
client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"})
|
|
|
|
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
# this is the DecisionTask representation you get from the real SWF
|
|
|
|
# after waiting 60s when there's no decision to be taken
|
|
|
|
resp.should.have.key("previousStartedEventId").equal(0)
|
|
|
|
resp.should.have.key("startedEventId").equal(0)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 20:11:07 +00:00
|
|
|
def test_poll_for_decision_task_on_non_existent_queue():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "non-existent-queue")
|
2021-02-12 13:01:42 +00:00
|
|
|
resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0})
|
2015-10-11 20:11:07 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_poll_for_decision_task_on_non_existent_queue_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "non-existent-queue"}
|
|
|
|
)
|
|
|
|
resp.should.have.key("previousStartedEventId").equal(0)
|
|
|
|
resp.should.have.key("startedEventId").equal(0)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 17:14:31 +00:00
|
|
|
def test_poll_for_decision_task_with_reverse_order():
|
|
|
|
conn = setup_workflow()
|
2019-10-31 15:44:26 +00:00
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True)
|
2015-10-11 17:14:31 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2017-02-24 02:37:43 +00:00
|
|
|
types.should.equal(
|
2019-10-31 15:44:26 +00:00
|
|
|
["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]
|
|
|
|
)
|
2015-10-11 20:14:16 +00:00
|
|
|
|
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_poll_for_decision_task_with_reverse_order_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}, reverseOrder=True
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(
|
|
|
|
["DecisionTaskStarted", "DecisionTaskScheduled", "WorkflowExecutionStarted"]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-10-11 20:14:16 +00:00
|
|
|
# CountPendingDecisionTasks endpoint
|
2021-09-21 22:00:20 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 20:14:16 +00:00
|
|
|
def test_count_pending_decision_tasks():
|
|
|
|
conn = setup_workflow()
|
|
|
|
conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
resp = conn.count_pending_decision_tasks("test-domain", "queue")
|
|
|
|
resp.should.equal({"count": 1, "truncated": False})
|
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_count_pending_decision_tasks_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"})
|
|
|
|
resp = client.count_pending_decision_tasks(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
resp.should.have.key("count").equal(1)
|
|
|
|
resp.should.have.key("truncated").equal(False)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-11 20:14:16 +00:00
|
|
|
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})
|
2015-10-12 09:08:52 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_count_pending_decision_tasks_on_non_existent_task_list_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.count_pending_decision_tasks(
|
|
|
|
domain="test-domain", taskList={"name": "non-existent"}
|
|
|
|
)
|
|
|
|
resp.should.have.key("count").equal(0)
|
|
|
|
resp.should.have.key("truncated").equal(False)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-24 10:05:42 +00:00
|
|
|
def test_count_pending_decision_tasks_after_decision_completes():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
conn.respond_decision_task_completed(resp["taskToken"])
|
|
|
|
|
|
|
|
resp = conn.count_pending_decision_tasks("test-domain", "queue")
|
|
|
|
resp.should.equal({"count": 0, "truncated": False})
|
|
|
|
|
2015-10-12 09:08:52 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_count_pending_decision_tasks_after_decision_completes_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
client.respond_decision_task_completed(taskToken=resp["taskToken"])
|
|
|
|
|
|
|
|
resp = client.count_pending_decision_tasks(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
resp.should.have.key("count").equal(0)
|
|
|
|
resp.should.have.key("truncated").equal(False)
|
|
|
|
|
|
|
|
|
2015-10-12 09:08:52 +00:00
|
|
|
# RespondDecisionTaskCompleted endpoint
|
2021-09-21 22:00:20 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-12 09:08:52 +00:00
|
|
|
def test_respond_decision_task_completed_with_no_decision():
|
|
|
|
conn = setup_workflow()
|
|
|
|
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2015-10-31 20:13:44 +00:00
|
|
|
resp = conn.respond_decision_task_completed(
|
2019-10-31 15:44:26 +00:00
|
|
|
task_token, execution_context="free-form context"
|
2015-10-31 20:13:44 +00:00
|
|
|
)
|
2015-10-12 09:08:52 +00:00
|
|
|
resp.should.be.none
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
resp = conn.get_workflow_execution_history(
|
2019-10-31 15:44:26 +00:00
|
|
|
"test-domain", conn.run_id, "uid-abcd1234"
|
|
|
|
)
|
2015-10-12 09:08:52 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2019-10-31 15:44:26 +00:00
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
]
|
|
|
|
)
|
2015-10-12 09:08:52 +00:00
|
|
|
evt = resp["events"][-1]
|
2019-10-31 15:44:26 +00:00
|
|
|
evt["decisionTaskCompletedEventAttributes"].should.equal(
|
|
|
|
{
|
|
|
|
"executionContext": "free-form context",
|
|
|
|
"scheduledEventId": 2,
|
|
|
|
"startedEventId": 3,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = conn.describe_workflow_execution("test-domain", conn.run_id, "uid-abcd1234")
|
2015-10-31 20:13:44 +00:00
|
|
|
resp["latestExecutionContext"].should.equal("free-form context")
|
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_no_decision_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=task_token, executionContext="free-form context"
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
evt = resp["events"][-1]
|
|
|
|
evt["decisionTaskCompletedEventAttributes"].should.equal(
|
|
|
|
{
|
|
|
|
"executionContext": "free-form context",
|
|
|
|
"scheduledEventId": 2,
|
|
|
|
"startedEventId": 3,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.describe_workflow_execution(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
resp["latestExecutionContext"].should.equal("free-form context")
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-12 09:08:52 +00:00
|
|
|
def test_respond_decision_task_completed_with_wrong_token():
|
|
|
|
conn = setup_workflow()
|
2016-02-02 19:02:37 +00:00
|
|
|
conn.poll_for_decision_task("test-domain", "queue")
|
2015-10-12 09:08:52 +00:00
|
|
|
conn.respond_decision_task_completed.when.called_with(
|
|
|
|
"not-a-correct-token"
|
2016-01-17 23:00:57 +00:00
|
|
|
).should.throw(SWFResponseError)
|
2015-10-12 09:08:52 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_wrong_token_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"})
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(taskToken="not-a-correct-token")
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
|
|
|
ex.value.response["Error"]["Message"].should.equal("Invalid token")
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-12 09:08:52 +00:00
|
|
|
def test_respond_decision_task_completed_on_close_workflow_execution():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
# bad: we're closing workflow execution manually, but endpoints are not
|
|
|
|
# coded for now..
|
2015-11-01 20:55:07 +00:00
|
|
|
wfe = swf_backend.domains[0].workflow_executions[-1]
|
2015-10-12 09:08:52 +00:00
|
|
|
wfe.execution_status = "CLOSED"
|
|
|
|
# /bad
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.respond_decision_task_completed.when.called_with(task_token).should.throw(
|
|
|
|
SWFResponseError
|
|
|
|
)
|
2015-10-12 09:08:52 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_on_close_workflow_execution_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
client.terminate_workflow_execution(domain="test-domain", workflowId="uid-abcd1234")
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token)
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault")
|
|
|
|
ex.value.response["Error"]["Message"].should.equal(
|
|
|
|
"Unknown execution: WorkflowExecution=[workflowId=uid-abcd1234, runId={}]".format(
|
|
|
|
client.run_id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-12 09:08:52 +00:00
|
|
|
def test_respond_decision_task_completed_with_task_already_completed():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
conn.respond_decision_task_completed(task_token)
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
conn.respond_decision_task_completed.when.called_with(task_token).should.throw(
|
|
|
|
SWFResponseError
|
|
|
|
)
|
2015-10-12 21:32:11 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_task_already_completed_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token)
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token)
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("UnknownResourceFault")
|
|
|
|
ex.value.response["Error"]["Message"].should.equal(
|
|
|
|
"Unknown decision task, scheduledEventId = 2"
|
|
|
|
)
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-12 21:32:11 +00:00
|
|
|
def test_respond_decision_task_completed_with_complete_workflow_execution():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "CompleteWorkflowExecution",
|
|
|
|
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
2015-10-12 21:32:11 +00:00
|
|
|
resp.should.be.none
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
resp = conn.get_workflow_execution_history(
|
2019-10-31 15:44:26 +00:00
|
|
|
"test-domain", conn.run_id, "uid-abcd1234"
|
|
|
|
)
|
2015-10-12 21:32:11 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2019-10-31 15:44:26 +00:00
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
"WorkflowExecutionCompleted",
|
|
|
|
]
|
|
|
|
)
|
2017-02-24 02:37:43 +00:00
|
|
|
resp["events"][-1]["workflowExecutionCompletedEventAttributes"][
|
2019-10-31 15:44:26 +00:00
|
|
|
"result"
|
|
|
|
].should.equal("foo bar")
|
2015-10-18 22:09:51 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_complete_workflow_execution_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "CompleteWorkflowExecution",
|
|
|
|
"completeWorkflowExecutionDecisionAttributes": {"result": "foo bar"},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token, decisions=decisions)
|
|
|
|
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
"WorkflowExecutionCompleted",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
resp["events"][-1]["workflowExecutionCompletedEventAttributes"][
|
|
|
|
"result"
|
|
|
|
].should.equal("foo bar")
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-18 22:09:51 +00:00
|
|
|
def test_respond_decision_task_completed_with_close_decision_not_last():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
2016-02-02 19:02:37 +00:00
|
|
|
{"decisionType": "CompleteWorkflowExecution"},
|
|
|
|
{"decisionType": "WeDontCare"},
|
2015-10-18 22:09:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
conn.respond_decision_task_completed.when.called_with(
|
|
|
|
task_token, decisions=decisions
|
2016-01-17 23:00:57 +00:00
|
|
|
).should.throw(SWFResponseError, r"Close must be last decision in list")
|
2015-10-18 22:09:51 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_close_decision_not_last_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
|
|
|
{"decisionType": "CompleteWorkflowExecution"},
|
|
|
|
{"decisionType": "WeDontCare"},
|
|
|
|
]
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=task_token, decisions=decisions
|
|
|
|
)
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
|
|
|
ex.value.response["Error"]["Message"].should.equal(
|
|
|
|
"Close must be last decision in list"
|
|
|
|
)
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-18 22:09:51 +00:00
|
|
|
def test_respond_decision_task_completed_with_invalid_decision_type():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
2016-02-02 19:02:37 +00:00
|
|
|
{"decisionType": "BadDecisionType"},
|
|
|
|
{"decisionType": "CompleteWorkflowExecution"},
|
2015-10-18 22:09:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
conn.respond_decision_task_completed.when.called_with(
|
2019-10-31 15:44:26 +00:00
|
|
|
task_token, decisions=decisions
|
|
|
|
).should.throw(
|
|
|
|
SWFResponseError,
|
|
|
|
r"Value 'BadDecisionType' at 'decisions.1.member.decisionType'",
|
2016-02-02 19:02:37 +00:00
|
|
|
)
|
|
|
|
|
2015-10-19 07:25:54 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_invalid_decision_type_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
|
|
|
{"decisionType": "BadDecisionType"},
|
|
|
|
{"decisionType": "CompleteWorkflowExecution"},
|
|
|
|
]
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=task_token, decisions=decisions
|
|
|
|
)
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
|
|
|
ex.value.response["Error"]["Message"].should.match(
|
|
|
|
"Value 'BadDecisionType' at 'decisions.1.member.decisionType'"
|
|
|
|
)
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-19 07:25:54 +00:00
|
|
|
def test_respond_decision_task_completed_with_missing_attributes():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "should trigger even with incorrect decision type",
|
2019-10-31 15:44:26 +00:00
|
|
|
"startTimerDecisionAttributes": {},
|
|
|
|
}
|
2015-10-19 07:25:54 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
conn.respond_decision_task_completed.when.called_with(
|
|
|
|
task_token, decisions=decisions
|
2016-02-02 19:02:37 +00:00
|
|
|
).should.throw(
|
|
|
|
SWFResponseError,
|
|
|
|
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
|
2019-10-31 15:44:26 +00:00
|
|
|
r"failed to satisfy constraint: Member must not be null",
|
2016-02-02 19:02:37 +00:00
|
|
|
)
|
|
|
|
|
2015-10-19 07:25:54 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-19 07:25:54 +00:00
|
|
|
def test_respond_decision_task_completed_with_missing_attributes_totally():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
decisions = [{"decisionType": "StartTimer"}]
|
2015-10-19 07:25:54 +00:00
|
|
|
|
|
|
|
conn.respond_decision_task_completed.when.called_with(
|
|
|
|
task_token, decisions=decisions
|
2016-02-02 19:02:37 +00:00
|
|
|
).should.throw(
|
|
|
|
SWFResponseError,
|
|
|
|
r"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' "
|
2019-10-31 15:44:26 +00:00
|
|
|
r"failed to satisfy constraint: Member must not be null",
|
2016-02-02 19:02:37 +00:00
|
|
|
)
|
|
|
|
|
2015-10-24 02:35:21 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_missing_attributes_totally_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [{"decisionType": "StartTimer"}]
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=task_token, decisions=decisions
|
|
|
|
)
|
|
|
|
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
|
|
|
ex.value.response["Error"]["Message"].should.match(
|
|
|
|
"Value null at 'decisions.1.member.startTimerDecisionAttributes.timerId' failed to satisfy constraint"
|
|
|
|
)
|
|
|
|
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-24 02:35:21 +00:00
|
|
|
def test_respond_decision_task_completed_with_fail_workflow_execution():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "FailWorkflowExecution",
|
|
|
|
"failWorkflowExecutionDecisionAttributes": {
|
|
|
|
"reason": "my rules",
|
|
|
|
"details": "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
2015-10-24 02:35:21 +00:00
|
|
|
resp.should.be.none
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
resp = conn.get_workflow_execution_history(
|
2019-10-31 15:44:26 +00:00
|
|
|
"test-domain", conn.run_id, "uid-abcd1234"
|
|
|
|
)
|
2015-10-24 02:35:21 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2019-10-31 15:44:26 +00:00
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
"WorkflowExecutionFailed",
|
|
|
|
]
|
|
|
|
)
|
2015-10-24 02:35:21 +00:00
|
|
|
attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"]
|
|
|
|
attrs["reason"].should.equal("my rules")
|
|
|
|
attrs["details"].should.equal("foo")
|
2015-10-25 23:43:35 +00:00
|
|
|
|
2016-02-02 19:02:37 +00:00
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
@mock_swf
|
|
|
|
def test_respond_decision_task_completed_with_fail_workflow_execution_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "FailWorkflowExecution",
|
|
|
|
"failWorkflowExecutionDecisionAttributes": {
|
|
|
|
"reason": "my rules",
|
|
|
|
"details": "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token, decisions=decisions)
|
|
|
|
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
|
|
|
types.should.equal(
|
|
|
|
[
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskCompleted",
|
|
|
|
"WorkflowExecutionFailed",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
attrs = resp["events"][-1]["workflowExecutionFailedEventAttributes"]
|
|
|
|
attrs["reason"].should.equal("my rules")
|
|
|
|
attrs["details"].should.equal("foo")
|
|
|
|
|
|
|
|
|
|
|
|
# Has boto3 equivalent
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_swf_deprecated
|
2015-10-31 20:13:44 +00:00
|
|
|
@freeze_time("2015-01-01 12:00:00")
|
2015-10-25 23:43:35 +00:00
|
|
|
def test_respond_decision_task_completed_with_schedule_activity_task():
|
|
|
|
conn = setup_workflow()
|
|
|
|
resp = conn.poll_for_decision_task("test-domain", "queue")
|
|
|
|
task_token = resp["taskToken"]
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
decisions = [
|
|
|
|
{
|
|
|
|
"decisionType": "ScheduleActivityTask",
|
|
|
|
"scheduleActivityTaskDecisionAttributes": {
|
|
|
|
"activityId": "my-activity-001",
|
|
|
|
"activityType": {"name": "test-activity", "version": "v1.1"},
|
|
|
|
"heartbeatTimeout": "60",
|
|
|
|
"input": "123",
|
|
|
|
"taskList": {"name": "my-task-list"},
|
2015-10-25 23:43:35 +00:00
|
|
|
},
|
|
|
|
}
|
2019-10-31 15:44:26 +00:00
|
|
|
]
|
|
|
|
resp = conn.respond_decision_task_completed(task_token, decisions=decisions)
|
2015-10-25 23:43:35 +00:00
|
|
|
resp.should.be.none
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
resp = conn.get_workflow_execution_history(
|
2019-10-31 15:44:26 +00:00
|
|
|
"test-domain", conn.run_id, "uid-abcd1234"
|
|
|
|
)
|
2015-10-25 23:43:35 +00:00
|
|
|
types = [evt["eventType"] for evt in resp["events"]]
|
2019-10-31 15:44:26 +00:00
|
|
|
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")
|
2015-11-03 08:09:00 +00:00
|
|
|
resp["latestActivityTaskTimestamp"].should.equal(1420113600.0)
|
2021-09-21 22:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_swf
|
|
|
|
@freeze_time("2015-01-01 12:00:00")
|
|
|
|
def test_respond_decision_task_completed_with_schedule_activity_task_boto3():
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
resp = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "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"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
client.respond_decision_task_completed(taskToken=task_token, decisions=decisions)
|
|
|
|
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "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"},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.describe_workflow_execution(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
resp["latestActivityTaskTimestamp"].should.be.a(datetime)
|
|
|
|
if not settings.TEST_SERVER_MODE:
|
|
|
|
ts = resp["latestActivityTaskTimestamp"].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
ts.should.equal("2015-01-01 12:00:00")
|