moto/tests/test_swf/models/test_decision_task.py
Jean-Baptiste Barth 61bb550052 Ensure activity and decision tasks cannot progress on a closed workflow
This is a second barrier because I'm a little nervous about this and I
don't want moto/swf to make any activity progress while in the real
world service, it's strictly impossible once the execution is closed.
Python doesn't seem to have any nice way of freezing an object so here
we go with a manual boundary...
2015-11-19 11:45:26 +01:00

75 lines
2.3 KiB
Python

from freezegun import freeze_time
from sure import expect
from moto.swf.exceptions import SWFWorkflowExecutionClosedError
from moto.swf.models import DecisionTask
from ..utils import make_workflow_execution
def test_decision_task_creation():
wfe = make_workflow_execution()
dt = DecisionTask(wfe, 123)
dt.workflow_execution.should.equal(wfe)
dt.state.should.equal("SCHEDULED")
dt.task_token.should_not.be.empty
dt.started_event_id.should.be.none
def test_decision_task_full_dict_representation():
wfe = make_workflow_execution()
wft = wfe.workflow_type
dt = DecisionTask(wfe, 123)
fd = dt.to_full_dict()
fd["events"].should.be.a("list")
fd["previousStartedEventId"].should.equal(0)
fd.should_not.contain("startedEventId")
fd.should.contain("taskToken")
fd["workflowExecution"].should.equal(wfe.to_short_dict())
fd["workflowType"].should.equal(wft.to_short_dict())
dt.start(1234)
fd = dt.to_full_dict()
fd["startedEventId"].should.equal(1234)
def test_decision_task_has_timedout():
wfe = make_workflow_execution()
dt = DecisionTask(wfe, 123)
dt.has_timedout().should.equal(False)
with freeze_time("2015-01-01 12:00:00"):
dt.start(1234)
dt.has_timedout().should.equal(False)
# activity task timeout is 300s == 5mins
with freeze_time("2015-01-01 12:06:00"):
dt.has_timedout().should.equal(True)
dt.complete()
dt.has_timedout().should.equal(False)
def test_decision_task_cannot_timeout_on_closed_workflow_execution():
with freeze_time("2015-01-01 12:00:00"):
wfe = make_workflow_execution()
wfe.start()
with freeze_time("2015-01-01 13:55:00"):
dt = DecisionTask(wfe, 123)
dt.start(1234)
with freeze_time("2015-01-01 14:10:00"):
dt.has_timedout().should.equal(True)
wfe.has_timedout().should.equal(True)
wfe.process_timeouts()
dt.has_timedout().should.equal(False)
def test_decision_task_cannot_change_state_on_closed_workflow_execution():
wfe = make_workflow_execution()
wfe.start()
task = DecisionTask(wfe, 123)
wfe.complete(123)
task.timeout.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)