2015-11-04 09:12:17 +00:00
|
|
|
from freezegun import freeze_time
|
2015-10-26 05:31:00 +00:00
|
|
|
from sure import expect
|
|
|
|
|
2015-11-05 00:12:51 +00:00
|
|
|
from moto.swf.exceptions import SWFWorkflowExecutionClosedError
|
2015-11-05 01:22:02 +00:00
|
|
|
from moto.swf.models import DecisionTask, Timeout
|
2015-10-26 05:31:00 +00:00
|
|
|
|
2015-11-05 01:47:05 +00:00
|
|
|
from ..utils import make_workflow_execution, process_first_timeout
|
2015-10-26 05:31:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2015-11-04 09:12:17 +00:00
|
|
|
|
2015-11-05 01:22:02 +00:00
|
|
|
def test_decision_task_first_timeout():
|
2015-11-04 09:12:17 +00:00
|
|
|
wfe = make_workflow_execution()
|
|
|
|
dt = DecisionTask(wfe, 123)
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.none
|
2015-11-04 09:12:17 +00:00
|
|
|
|
|
|
|
with freeze_time("2015-01-01 12:00:00"):
|
|
|
|
dt.start(1234)
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.none
|
2015-11-04 09:12:17 +00:00
|
|
|
|
|
|
|
# activity task timeout is 300s == 5mins
|
|
|
|
with freeze_time("2015-01-01 12:06:00"):
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.a(Timeout)
|
2015-11-04 09:12:17 +00:00
|
|
|
|
|
|
|
dt.complete()
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.none
|
2015-11-04 21:35:45 +00:00
|
|
|
|
|
|
|
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"):
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.a(Timeout)
|
|
|
|
wfe.first_timeout().should.be.a(Timeout)
|
2015-11-05 01:47:05 +00:00
|
|
|
process_first_timeout(wfe)
|
2015-11-05 01:22:02 +00:00
|
|
|
dt.first_timeout().should.be.none
|
2015-11-05 00:12:51 +00:00
|
|
|
|
|
|
|
def test_decision_task_cannot_change_state_on_closed_workflow_execution():
|
|
|
|
wfe = make_workflow_execution()
|
|
|
|
wfe.start()
|
|
|
|
task = DecisionTask(wfe, 123)
|
|
|
|
|
|
|
|
wfe.complete(123)
|
|
|
|
|
2015-11-05 01:22:02 +00:00
|
|
|
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(SWFWorkflowExecutionClosedError)
|
2015-11-05 00:12:51 +00:00
|
|
|
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|