| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | from datetime import datetime | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | from freezegun import freeze_time | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | from unittest import SkipTest | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | from moto import mock_swf_deprecated, mock_swf, settings | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from ..utils import setup_workflow, SCHEDULE_ACTIVITY_TASK_DECISION | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | from ..utils import setup_workflow_boto3 | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Activity Task Heartbeat timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 5 mins | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | def test_activity_task_heartbeat_timeout(): | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:00:00"): | 
					
						
							|  |  |  |         conn = setup_workflow() | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         decision_token = conn.poll_for_decision_task("test-domain", "queue")[ | 
					
						
							|  |  |  |             "taskToken" | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |         conn.respond_decision_task_completed( | 
					
						
							|  |  |  |             decision_token, decisions=[SCHEDULE_ACTIVITY_TASK_DECISION] | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         conn.poll_for_activity_task( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", "activity-task-list", identity="surprise" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:04:30"): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  |         resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:05:30"): | 
					
						
							|  |  |  |         # => Activity Task Heartbeat timeout reached!! | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut") | 
					
						
							|  |  |  |         attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"] | 
					
						
							|  |  |  |         attrs["timeoutType"].should.equal("HEARTBEAT") | 
					
						
							| 
									
										
										
										
											2015-11-05 02:40:16 +01:00
										 |  |  |         # checks that event has been emitted at 12:05:00, not 12:05:30 | 
					
						
							| 
									
										
										
										
											2015-12-09 21:33:42 +01:00
										 |  |  |         resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0) | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled") | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | # Activity Task Heartbeat timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 5 mins | 
					
						
							|  |  |  | @mock_swf | 
					
						
							|  |  |  | 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", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:04:30"): | 
					
						
							|  |  |  |         resp = client.get_workflow_execution_history( | 
					
						
							|  |  |  |             domain="test-domain", | 
					
						
							|  |  |  |             execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:05:30"): | 
					
						
							|  |  |  |         # => Activity Task Heartbeat timeout reached!! | 
					
						
							|  |  |  |         resp = client.get_workflow_execution_history( | 
					
						
							|  |  |  |             domain="test-domain", | 
					
						
							|  |  |  |             execution={"runId": client.run_id, "workflowId": "uid-abcd1234"}, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut") | 
					
						
							|  |  |  |         attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"] | 
					
						
							|  |  |  |         attrs["timeoutType"].should.equal("HEARTBEAT") | 
					
						
							|  |  |  |         # checks that event has been emitted at 12:05:00, not 12:05:30 | 
					
						
							|  |  |  |         resp["events"][-2]["eventTimestamp"].should.be.a(datetime) | 
					
						
							|  |  |  |         ts = resp["events"][-2]["eventTimestamp"].strftime("%Y-%m-%d %H:%M:%S") | 
					
						
							|  |  |  |         ts.should.equal("2015-01-01 12:05:00") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  | # Decision Task Start to Close timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 5 mins | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  | def test_decision_task_start_to_close_timeout(): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:00:00"): | 
					
						
							|  |  |  |         conn = setup_workflow() | 
					
						
							|  |  |  |         conn.poll_for_decision_task("test-domain", "queue")["taskToken"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:04:30"): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         event_types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							|  |  |  |             ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:05:30"): | 
					
						
							|  |  |  |         # => Decision Task Start to Close timeout reached!! | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         event_types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             [ | 
					
						
							|  |  |  |                 "WorkflowExecutionStarted", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |                 "DecisionTaskStarted", | 
					
						
							|  |  |  |                 "DecisionTaskTimedOut", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2015-11-04 10:12:17 +01:00
										 |  |  |         ) | 
					
						
							|  |  |  |         attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         attrs.should.equal( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "scheduledEventId": 2, | 
					
						
							|  |  |  |                 "startedEventId": 3, | 
					
						
							|  |  |  |                 "timeoutType": "START_TO_CLOSE", | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-05 02:40:16 +01:00
										 |  |  |         # checks that event has been emitted at 12:05:00, not 12:05:30 | 
					
						
							| 
									
										
										
										
											2015-12-09 21:33:42 +01:00
										 |  |  |         resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0) | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | # Decision Task Start to Close timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 5 mins | 
					
						
							|  |  |  | @mock_swf | 
					
						
							|  |  |  | def test_decision_task_start_to_close_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() | 
					
						
							|  |  |  |         client.poll_for_decision_task(domain="test-domain", taskList={"name": "queue"}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:04:30"): | 
					
						
							|  |  |  |         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"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							|  |  |  |             ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:05:30"): | 
					
						
							|  |  |  |         # => 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"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 "WorkflowExecutionStarted", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |                 "DecisionTaskStarted", | 
					
						
							|  |  |  |                 "DecisionTaskTimedOut", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"] | 
					
						
							|  |  |  |         attrs.should.equal( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "scheduledEventId": 2, | 
					
						
							|  |  |  |                 "startedEventId": 3, | 
					
						
							|  |  |  |                 "timeoutType": "START_TO_CLOSE", | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         # checks that event has been emitted at 12:05:00, not 12:05:30 | 
					
						
							|  |  |  |         resp["events"][-2]["eventTimestamp"].should.be.a(datetime) | 
					
						
							|  |  |  |         ts = resp["events"][-2]["eventTimestamp"].strftime("%Y-%m-%d %H:%M:%S") | 
					
						
							|  |  |  |         ts.should.equal("2015-01-01 12:05:00") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | # Workflow Execution Start to Close timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 2 hours | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | # Has boto3 equivalent | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_swf_deprecated | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | def test_workflow_execution_start_to_close_timeout(): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 12:00:00"): | 
					
						
							|  |  |  |         conn = setup_workflow() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 13:59:30"): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         event_types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         event_types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 14:00:30"): | 
					
						
							|  |  |  |         # => Workflow Execution Start to Close timeout reached!! | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         resp = conn.get_workflow_execution_history( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "test-domain", conn.run_id, "uid-abcd1234" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         event_types = [evt["eventType"] for evt in resp["events"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             [ | 
					
						
							|  |  |  |                 "WorkflowExecutionStarted", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |                 "WorkflowExecutionTimedOut", | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  |         ) | 
					
						
							|  |  |  |         attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         attrs.should.equal({"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"}) | 
					
						
							| 
									
										
										
										
											2015-11-05 02:40:16 +01:00
										 |  |  |         # checks that event has been emitted at 14:00:00, not 14:00:30 | 
					
						
							| 
									
										
										
										
											2015-12-09 21:33:42 +01:00
										 |  |  |         resp["events"][-1]["eventTimestamp"].should.equal(1420120800.0) | 
					
						
							| 
									
										
										
										
											2021-09-21 22:00:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Workflow Execution Start to Close timeout | 
					
						
							|  |  |  | # Default value in workflow helpers: 2 hours | 
					
						
							|  |  |  | @mock_swf | 
					
						
							|  |  |  | def test_workflow_execution_start_to_close_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() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 13:59:30"): | 
					
						
							|  |  |  |         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"]] | 
					
						
							|  |  |  |         event_types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with freeze_time("2015-01-01 14:00:30"): | 
					
						
							|  |  |  |         # => 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"]] | 
					
						
							|  |  |  |         event_types.should.equal( | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 "WorkflowExecutionStarted", | 
					
						
							|  |  |  |                 "DecisionTaskScheduled", | 
					
						
							|  |  |  |                 "WorkflowExecutionTimedOut", | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"] | 
					
						
							|  |  |  |         attrs.should.equal({"childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"}) | 
					
						
							|  |  |  |         # checks that event has been emitted at 14:00:00, not 14:00:30 | 
					
						
							|  |  |  |         resp["events"][-1]["eventTimestamp"].should.be.a(datetime) | 
					
						
							|  |  |  |         ts = resp["events"][-1]["eventTimestamp"].strftime("%Y-%m-%d %H:%M:%S") | 
					
						
							|  |  |  |         ts.should.equal("2015-01-01 14:00:00") |