Add SWF endpoint RecordActivityTaskHeartbeat
This commit is contained in:
parent
804d2e91b5
commit
f576f3765c
9 changed files with 94 additions and 12 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from freezegun import freeze_time
|
||||
from sure import expect
|
||||
|
||||
from moto.swf.models import (
|
||||
|
|
@ -58,3 +59,22 @@ def test_activity_task_full_dict_representation():
|
|||
at.start(1234)
|
||||
fd = at.to_full_dict()
|
||||
fd["startedEventId"].should.equal(1234)
|
||||
|
||||
def test_activity_task_reset_heartbeat_clock():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
task = ActivityTask(
|
||||
activity_id="my-activity-123",
|
||||
activity_type="foo",
|
||||
input="optional",
|
||||
scheduled_event_id=117,
|
||||
workflow_execution=wfe,
|
||||
)
|
||||
|
||||
task.last_heartbeat_timestamp.should.equal(1420110000.0)
|
||||
|
||||
with freeze_time("2015-01-01 13:00:00"):
|
||||
task.reset_heartbeat_clock()
|
||||
|
||||
task.last_heartbeat_timestamp.should.equal(1420113600.0)
|
||||
|
|
|
|||
|
|
@ -171,3 +171,31 @@ def test_respond_activity_task_completed_with_wrong_token():
|
|||
conn.respond_activity_task_failed.when.called_with(
|
||||
"not-a-correct-token"
|
||||
).should.throw(SWFValidationException, "Invalid token")
|
||||
|
||||
|
||||
# RecordActivityTaskHeartbeat endpoint
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
resp = conn.record_activity_task_heartbeat(activity_token, details="some progress details")
|
||||
# TODO: check that "details" are reflected in ActivityTaskTimedOut event when a timeout occurs
|
||||
resp.should.equal({"cancelRequested": False})
|
||||
|
||||
@mock_swf
|
||||
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"]
|
||||
|
||||
conn.record_activity_task_heartbeat.when.called_with(
|
||||
"bad-token", details="some progress details"
|
||||
).should.throw(SWFValidationException)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
from freezegun import freeze_time
|
||||
from sure import expect
|
||||
from moto.swf.utils import decapitalize
|
||||
|
||||
from moto.swf.utils import (
|
||||
decapitalize,
|
||||
now_timestamp,
|
||||
)
|
||||
|
||||
|
||||
def test_decapitalize():
|
||||
cases = {
|
||||
|
|
@ -9,3 +15,7 @@ def test_decapitalize():
|
|||
}
|
||||
for before, after in cases.iteritems():
|
||||
decapitalize(before).should.equal(after)
|
||||
|
||||
@freeze_time("2015-01-01 12:00:00")
|
||||
def test_now_timestamp():
|
||||
now_timestamp().should.equal(1420110000.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue