Refactor timeouts processing so it will be easier to compute them in order
This commit is contained in:
parent
61bb550052
commit
d618585790
9 changed files with 101 additions and 52 deletions
|
|
@ -5,6 +5,7 @@ from moto.swf.exceptions import SWFWorkflowExecutionClosedError
|
|||
from moto.swf.models import (
|
||||
ActivityTask,
|
||||
ActivityType,
|
||||
Timeout,
|
||||
)
|
||||
|
||||
from ..utils import make_workflow_execution, ACTIVITY_TASK_TIMEOUTS
|
||||
|
|
@ -83,7 +84,7 @@ def test_activity_task_reset_heartbeat_clock():
|
|||
|
||||
task.last_heartbeat_timestamp.should.equal(1420117200.0)
|
||||
|
||||
def test_activity_task_has_timedout():
|
||||
def test_activity_task_first_timeout():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
|
|
@ -95,11 +96,11 @@ def test_activity_task_has_timedout():
|
|||
timeouts=ACTIVITY_TASK_TIMEOUTS,
|
||||
workflow_execution=wfe,
|
||||
)
|
||||
task.has_timedout().should.equal(False)
|
||||
task.first_timeout().should.be.none
|
||||
|
||||
# activity task timeout is 300s == 5mins
|
||||
with freeze_time("2015-01-01 12:06:00"):
|
||||
task.has_timedout().should.equal(True)
|
||||
task.first_timeout().should.be.a(Timeout)
|
||||
task.process_timeouts()
|
||||
task.state.should.equal("TIMED_OUT")
|
||||
task.timeout_type.should.equal("HEARTBEAT")
|
||||
|
|
@ -120,10 +121,10 @@ def test_activity_task_cannot_timeout_on_closed_workflow_execution():
|
|||
)
|
||||
|
||||
with freeze_time("2015-01-01 14:10:00"):
|
||||
task.has_timedout().should.equal(True)
|
||||
wfe.has_timedout().should.equal(True)
|
||||
task.first_timeout().should.be.a(Timeout)
|
||||
wfe.first_timeout().should.be.a(Timeout)
|
||||
wfe.process_timeouts()
|
||||
task.has_timedout().should.equal(False)
|
||||
task.first_timeout().should.be.none
|
||||
|
||||
def test_activity_task_cannot_change_state_on_closed_workflow_execution():
|
||||
wfe = make_workflow_execution()
|
||||
|
|
@ -139,6 +140,6 @@ def test_activity_task_cannot_change_state_on_closed_workflow_execution():
|
|||
)
|
||||
wfe.complete(123)
|
||||
|
||||
task.timeout.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|
||||
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(SWFWorkflowExecutionClosedError)
|
||||
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|
||||
task.fail.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from freezegun import freeze_time
|
|||
from sure import expect
|
||||
|
||||
from moto.swf.exceptions import SWFWorkflowExecutionClosedError
|
||||
from moto.swf.models import DecisionTask
|
||||
from moto.swf.models import DecisionTask, Timeout
|
||||
|
||||
from ..utils import make_workflow_execution
|
||||
|
||||
|
|
@ -32,21 +32,21 @@ def test_decision_task_full_dict_representation():
|
|||
fd = dt.to_full_dict()
|
||||
fd["startedEventId"].should.equal(1234)
|
||||
|
||||
def test_decision_task_has_timedout():
|
||||
def test_decision_task_first_timeout():
|
||||
wfe = make_workflow_execution()
|
||||
dt = DecisionTask(wfe, 123)
|
||||
dt.has_timedout().should.equal(False)
|
||||
dt.first_timeout().should.be.none
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
dt.start(1234)
|
||||
dt.has_timedout().should.equal(False)
|
||||
dt.first_timeout().should.be.none
|
||||
|
||||
# activity task timeout is 300s == 5mins
|
||||
with freeze_time("2015-01-01 12:06:00"):
|
||||
dt.has_timedout().should.equal(True)
|
||||
dt.first_timeout().should.be.a(Timeout)
|
||||
|
||||
dt.complete()
|
||||
dt.has_timedout().should.equal(False)
|
||||
dt.first_timeout().should.be.none
|
||||
|
||||
def test_decision_task_cannot_timeout_on_closed_workflow_execution():
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
|
|
@ -58,10 +58,10 @@ def test_decision_task_cannot_timeout_on_closed_workflow_execution():
|
|||
dt.start(1234)
|
||||
|
||||
with freeze_time("2015-01-01 14:10:00"):
|
||||
dt.has_timedout().should.equal(True)
|
||||
wfe.has_timedout().should.equal(True)
|
||||
dt.first_timeout().should.be.a(Timeout)
|
||||
wfe.first_timeout().should.be.a(Timeout)
|
||||
wfe.process_timeouts()
|
||||
dt.has_timedout().should.equal(False)
|
||||
dt.first_timeout().should.be.none
|
||||
|
||||
def test_decision_task_cannot_change_state_on_closed_workflow_execution():
|
||||
wfe = make_workflow_execution()
|
||||
|
|
@ -70,5 +70,5 @@ def test_decision_task_cannot_change_state_on_closed_workflow_execution():
|
|||
|
||||
wfe.complete(123)
|
||||
|
||||
task.timeout.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|
||||
task.timeout.when.called_with(Timeout(task, 0, "foo")).should.throw(SWFWorkflowExecutionClosedError)
|
||||
task.complete.when.called_with().should.throw(SWFWorkflowExecutionClosedError)
|
||||
|
|
|
|||
18
tests/test_swf/models/test_timeout.py
Normal file
18
tests/test_swf/models/test_timeout.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from freezegun import freeze_time
|
||||
from sure import expect
|
||||
|
||||
from moto.swf.models import Timeout, WorkflowExecution
|
||||
|
||||
from ..utils import make_workflow_execution
|
||||
|
||||
def test_timeout_creation():
|
||||
wfe = make_workflow_execution()
|
||||
|
||||
# epoch 1420113600 == "2015-01-01 13:00:00"
|
||||
timeout = Timeout(wfe, 1420117200, "START_TO_CLOSE")
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
timeout.reached.should.be.falsy
|
||||
|
||||
with freeze_time("2015-01-01 13:00:00"):
|
||||
timeout.reached.should.be.truthy
|
||||
|
|
@ -3,6 +3,7 @@ from freezegun import freeze_time
|
|||
|
||||
from moto.swf.models import (
|
||||
ActivityType,
|
||||
Timeout,
|
||||
WorkflowType,
|
||||
WorkflowExecution,
|
||||
)
|
||||
|
|
@ -106,7 +107,7 @@ def test_workflow_execution_medium_dict_representation():
|
|||
md["workflowType"].should.equal(wf_type.to_short_dict())
|
||||
md["startTimestamp"].should.be.a('float')
|
||||
md["executionStatus"].should.equal("OPEN")
|
||||
md["cancelRequested"].should.equal(False)
|
||||
md["cancelRequested"].should.be.falsy
|
||||
md.should_not.contain("tagList")
|
||||
|
||||
wfe.tag_list = ["foo", "bar", "baz"]
|
||||
|
|
@ -395,14 +396,14 @@ def test_terminate():
|
|||
# take default child_policy if not provided (as here)
|
||||
last_event.child_policy.should.equal("ABANDON")
|
||||
|
||||
def test_has_timedout():
|
||||
def test_first_timeout():
|
||||
wfe = make_workflow_execution()
|
||||
wfe.has_timedout().should.equal(False)
|
||||
wfe.first_timeout().should.be.none
|
||||
|
||||
with freeze_time("2015-01-01 12:00:00"):
|
||||
wfe.start()
|
||||
wfe.has_timedout().should.equal(False)
|
||||
wfe.first_timeout().should.be.none
|
||||
|
||||
with freeze_time("2015-01-01 14:01"):
|
||||
# 2 hours timeout reached
|
||||
wfe.has_timedout().should.equal(True)
|
||||
wfe.first_timeout().should.be.a(Timeout)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue