Add SWF endpoint PollForActivityTask
This commit is contained in:
parent
d650f71d9c
commit
761ab816f9
8 changed files with 196 additions and 37 deletions
|
|
@ -1,6 +1,9 @@
|
|||
from sure import expect
|
||||
|
||||
from moto.swf.models import ActivityTask
|
||||
from moto.swf.models import (
|
||||
ActivityTask,
|
||||
ActivityType,
|
||||
)
|
||||
|
||||
from ..utils import make_workflow_execution
|
||||
|
||||
|
|
@ -11,6 +14,7 @@ def test_activity_task_creation():
|
|||
activity_id="my-activity-123",
|
||||
activity_type="foo",
|
||||
input="optional",
|
||||
scheduled_event_id=117,
|
||||
workflow_execution=wfe,
|
||||
)
|
||||
task.workflow_execution.should.equal(wfe)
|
||||
|
|
@ -24,3 +28,27 @@ def test_activity_task_creation():
|
|||
|
||||
task.complete()
|
||||
task.state.should.equal("COMPLETED")
|
||||
|
||||
def test_activity_task_full_dict_representation():
|
||||
wfe = make_workflow_execution()
|
||||
wft = wfe.workflow_type
|
||||
at = ActivityTask(
|
||||
activity_id="my-activity-123",
|
||||
activity_type=ActivityType("foo", "v1.0"),
|
||||
input="optional",
|
||||
scheduled_event_id=117,
|
||||
workflow_execution=wfe,
|
||||
)
|
||||
at.start(1234)
|
||||
|
||||
fd = at.to_full_dict()
|
||||
fd["activityId"].should.equal("my-activity-123")
|
||||
fd["activityType"]["version"].should.equal("v1.0")
|
||||
fd["input"].should.equal("optional")
|
||||
fd["startedEventId"].should.equal(1234)
|
||||
fd.should.contain("taskToken")
|
||||
fd["workflowExecution"].should.equal(wfe.to_short_dict())
|
||||
|
||||
at.start(1234)
|
||||
fd = at.to_full_dict()
|
||||
fd["startedEventId"].should.equal(1234)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,16 @@ from ..utils import (
|
|||
)
|
||||
|
||||
|
||||
VALID_ACTIVITY_TASK_ATTRIBUTES = {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||
"taskList": { "name": "task-list-name" },
|
||||
"scheduleToStartTimeout": "600",
|
||||
"scheduleToCloseTimeout": "600",
|
||||
"startToCloseTimeout": "600",
|
||||
"heartbeatTimeout": "300",
|
||||
}
|
||||
|
||||
def test_workflow_execution_creation():
|
||||
domain = get_basic_domain()
|
||||
wft = get_basic_workflow_type()
|
||||
|
|
@ -187,15 +197,7 @@ def test_workflow_execution_fail():
|
|||
|
||||
def test_workflow_execution_schedule_activity_task():
|
||||
wfe = make_workflow_execution()
|
||||
wfe.schedule_activity_task(123, {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||
"taskList": { "name": "task-list-name" },
|
||||
"scheduleToStartTimeout": "600",
|
||||
"scheduleToCloseTimeout": "600",
|
||||
"startToCloseTimeout": "600",
|
||||
"heartbeatTimeout": "300",
|
||||
})
|
||||
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
|
||||
|
||||
wfe.open_counts["openActivityTasks"].should.equal(1)
|
||||
last_event = wfe.events()[-1]
|
||||
|
|
@ -330,29 +332,23 @@ def test_workflow_execution_schedule_activity_task_failure_triggers_new_decision
|
|||
def test_workflow_execution_schedule_activity_task_with_same_activity_id():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
wfe.schedule_activity_task(123, {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||
"taskList": { "name": "task-list-name" },
|
||||
"scheduleToStartTimeout": "600",
|
||||
"scheduleToCloseTimeout": "600",
|
||||
"startToCloseTimeout": "600",
|
||||
"heartbeatTimeout": "300",
|
||||
})
|
||||
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
|
||||
wfe.open_counts["openActivityTasks"].should.equal(1)
|
||||
last_event = wfe.events()[-1]
|
||||
last_event.event_type.should.equal("ActivityTaskScheduled")
|
||||
|
||||
wfe.schedule_activity_task(123, {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||
"taskList": { "name": "task-list-name" },
|
||||
"scheduleToStartTimeout": "600",
|
||||
"scheduleToCloseTimeout": "600",
|
||||
"startToCloseTimeout": "600",
|
||||
"heartbeatTimeout": "300",
|
||||
})
|
||||
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
|
||||
wfe.open_counts["openActivityTasks"].should.equal(1)
|
||||
last_event = wfe.events()[-1]
|
||||
last_event.event_type.should.equal("ScheduleActivityTaskFailed")
|
||||
last_event.cause.should.equal("ACTIVITY_ID_ALREADY_IN_USE")
|
||||
|
||||
def test_workflow_execution_start_activity_task():
|
||||
wfe = make_workflow_execution()
|
||||
wfe.schedule_activity_task(123, VALID_ACTIVITY_TASK_ATTRIBUTES)
|
||||
task_token = wfe.activity_tasks[-1].task_token
|
||||
wfe.start_activity_task(task_token, identity="worker01")
|
||||
task = wfe.activity_tasks[-1]
|
||||
task.state.should.equal("STARTED")
|
||||
wfe.events()[-1].event_type.should.equal("ActivityTaskStarted")
|
||||
wfe.events()[-1].identity.should.equal("worker01")
|
||||
|
|
|
|||
46
tests/test_swf/responses/test_activity_tasks.py
Normal file
46
tests/test_swf/responses/test_activity_tasks.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import boto
|
||||
from sure import expect
|
||||
|
||||
from moto import mock_swf
|
||||
from moto.swf.exceptions import SWFUnknownResourceFault
|
||||
|
||||
from ..utils import setup_workflow
|
||||
|
||||
|
||||
# PollForActivityTask endpoint
|
||||
@mock_swf
|
||||
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=[
|
||||
{
|
||||
"decisionType": "ScheduleActivityTask",
|
||||
"scheduleActivityTaskDecisionAttributes": {
|
||||
"activityId": "my-activity-001",
|
||||
"activityType": { "name": "test-activity", "version": "v1.1" },
|
||||
"taskList": { "name": "activity-task-list" },
|
||||
}
|
||||
}
|
||||
])
|
||||
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["events"][-1]["eventType"].should.equal("ActivityTaskStarted")
|
||||
resp["events"][-1]["activityTaskStartedEventAttributes"].should.equal(
|
||||
{ "identity": "surprise", "scheduledEventId": 5 }
|
||||
)
|
||||
|
||||
@mock_swf
|
||||
def test_poll_for_activity_task_when_none():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_activity_task("test-domain", "activity-task-list")
|
||||
resp.should.equal({"startedEventId": 0})
|
||||
|
||||
@mock_swf
|
||||
def test_poll_for_activity_task_on_non_existent_queue():
|
||||
conn = setup_workflow()
|
||||
resp = conn.poll_for_activity_task("test-domain", "non-existent-queue")
|
||||
resp.should.equal({"startedEventId": 0})
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue