2021-09-21 22:00:20 +00:00
|
|
|
from datetime import datetime
|
2023-08-12 07:59:33 +00:00
|
|
|
from unittest import SkipTest
|
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
from dateutil.parser import parse as dtparse
|
2015-11-02 23:28:13 +00:00
|
|
|
from freezegun import freeze_time
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws, settings
|
2015-11-02 23:28:13 +00:00
|
|
|
|
2023-11-30 15:55:51 +00:00
|
|
|
from ..utils import SCHEDULE_ACTIVITY_TASK_DECISION, setup_workflow_boto3
|
2015-11-02 23:28:13 +00:00
|
|
|
|
|
|
|
|
2021-09-21 22:00:20 +00:00
|
|
|
# Activity Task Heartbeat timeout
|
|
|
|
# Default value in workflow helpers: 5 mins
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-09-21 22:00:20 +00:00
|
|
|
def test_activity_task_heartbeat_timeout_boto3():
|
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest("Unable to manipulate time in ServerMode")
|
|
|
|
with freeze_time("2015-01-01 12:00:00"):
|
|
|
|
client = setup_workflow_boto3()
|
|
|
|
decision_token = client.poll_for_decision_task(
|
|
|
|
domain="test-domain", taskList={"name": "queue"}
|
|
|
|
)["taskToken"]
|
|
|
|
client.respond_decision_task_completed(
|
|
|
|
taskToken=decision_token, decisions=[SCHEDULE_ACTIVITY_TASK_DECISION]
|
|
|
|
)
|
|
|
|
client.poll_for_activity_task(
|
|
|
|
domain="test-domain",
|
|
|
|
taskList={"name": "activity-task-list"},
|
|
|
|
identity="surprise",
|
|
|
|
)
|
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:04:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
2023-08-12 07:59:33 +00:00
|
|
|
assert resp["events"][-1]["eventType"] == "ActivityTaskStarted"
|
2021-09-21 22:00:20 +00:00
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:05:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
# => Activity Task Heartbeat timeout reached!!
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
|
2023-08-12 07:59:33 +00:00
|
|
|
assert resp["events"][-2]["eventType"] == "ActivityTaskTimedOut"
|
2021-09-21 22:00:20 +00:00
|
|
|
attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert attrs["timeoutType"] == "HEARTBEAT"
|
2021-09-21 22:00:20 +00:00
|
|
|
# checks that event has been emitted at 12:05:00, not 12:05:30
|
2023-08-12 07:59:33 +00:00
|
|
|
assert isinstance(resp["events"][-2]["eventTimestamp"], datetime)
|
2022-04-19 22:22:49 +00:00
|
|
|
ts = resp["events"][-2]["eventTimestamp"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert ts == dtparse("2015-01-01 12:05:00 UTC")
|
2021-09-21 22:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Decision Task Start to Close timeout
|
|
|
|
# Default value in workflow helpers: 5 mins
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-09-21 22:00:20 +00:00
|
|
|
def test_decision_task_start_to_close_timeout_boto3():
|
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest("Unable to manipulate time in ServerMode")
|
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:00:00 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
client = setup_workflow_boto3()
|
|
|
|
client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"})
|
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:04:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
|
|
|
|
event_types = [evt["eventType"] for evt in resp["events"]]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert event_types == [
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
]
|
2021-09-21 22:00:20 +00:00
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:05:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
# => Decision Task Start to Close timeout reached!!
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
|
|
|
|
event_types = [evt["eventType"] for evt in resp["events"]]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert event_types == [
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"DecisionTaskStarted",
|
|
|
|
"DecisionTaskTimedOut",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
]
|
2021-09-21 22:00:20 +00:00
|
|
|
attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert attrs == {
|
|
|
|
"scheduledEventId": 2,
|
|
|
|
"startedEventId": 3,
|
|
|
|
"timeoutType": "START_TO_CLOSE",
|
|
|
|
}
|
2021-09-21 22:00:20 +00:00
|
|
|
# checks that event has been emitted at 12:05:00, not 12:05:30
|
2023-08-12 07:59:33 +00:00
|
|
|
assert isinstance(resp["events"][-2]["eventTimestamp"], datetime)
|
2022-04-19 22:22:49 +00:00
|
|
|
ts = resp["events"][-2]["eventTimestamp"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert ts == dtparse("2015-01-01 12:05:00 UTC")
|
2021-09-21 22:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Workflow Execution Start to Close timeout
|
|
|
|
# Default value in workflow helpers: 2 hours
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-09-21 22:00:20 +00:00
|
|
|
def test_workflow_execution_start_to_close_timeout_boto3():
|
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest("Unable to manipulate time in ServerMode")
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 12:00:00 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
client = setup_workflow_boto3()
|
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 13:59:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
|
|
|
|
event_types = [evt["eventType"] for evt in resp["events"]]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert event_types == ["WorkflowExecutionStarted", "DecisionTaskScheduled"]
|
2021-09-21 22:00:20 +00:00
|
|
|
|
2022-04-19 22:22:49 +00:00
|
|
|
with freeze_time("2015-01-01 14:00:30 UTC"):
|
2021-09-21 22:00:20 +00:00
|
|
|
# => Workflow Execution Start to Close timeout reached!!
|
|
|
|
resp = client.get_workflow_execution_history(
|
|
|
|
domain="test-domain",
|
|
|
|
execution={"runId": client.run_id, "workflowId": "uid-abcd1234"},
|
|
|
|
)
|
|
|
|
|
|
|
|
event_types = [evt["eventType"] for evt in resp["events"]]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert event_types == [
|
|
|
|
"WorkflowExecutionStarted",
|
|
|
|
"DecisionTaskScheduled",
|
|
|
|
"WorkflowExecutionTimedOut",
|
|
|
|
]
|
2021-09-21 22:00:20 +00:00
|
|
|
attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert attrs == {"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"}
|
2021-09-21 22:00:20 +00:00
|
|
|
# checks that event has been emitted at 14:00:00, not 14:00:30
|
2023-08-12 07:59:33 +00:00
|
|
|
assert isinstance(resp["events"][-1]["eventTimestamp"], datetime)
|
2022-04-19 22:22:49 +00:00
|
|
|
ts = resp["events"][-1]["eventTimestamp"]
|
2023-08-12 07:59:33 +00:00
|
|
|
assert ts == dtparse("2015-01-01 14:00:00 UTC")
|