Best Python code snippet using localstack_python
test_simple_workflows.py
Source:test_simple_workflows.py
...24 worker.stop()25 worker.join()26 time.sleep(2)27 self.assertEqual("TestExecution", starter.wait_for_completion(instance, 1))28 hist = self.get_workflow_execution_history()29 self.assertEqual(len(hist), 5)30 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')31 self.assertEqual(self.serializer.loads(32 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 'TestExecution')33 def test_no_activities_failure(self):34 class NoActivitiesFailureWorkflow(WorkflowDefinition):35 @execute(version='1.1', execution_start_to_close_timeout=60)36 def execute(self, arg1):37 raise RuntimeError("ExecutionFailed")38 worker = WorkflowWorker(39 self.session, self.region, self.domain, self.task_list, NoActivitiesFailureWorkflow)40 with workflow_starter(self.session, self.region, self.domain, self.task_list) as starter:41 instance = NoActivitiesFailureWorkflow.execute(arg1="TestExecution")42 self.workflow_execution = instance.workflow_execution43 worker.run_once()44 time.sleep(1)45 try:46 starter.wait_for_completion(instance, 1)47 except WorkflowFailedError as err:48 self.assertEqual(RuntimeError, type(err.cause))49 else:50 self.fail("Should never succeed")51 hist = self.get_workflow_execution_history()52 self.assertEqual(len(hist), 5)53 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionFailed')54 self.assertEqual(str(self.serializer.loads(55 hist[-1]['workflowExecutionFailedEventAttributes']['details'])[0]), "ExecutionFailed")56 def test_no_activities_with_state(self):57 class NoActivitiesWorkflow(WorkflowDefinition):58 @execute(version='1.2', execution_start_to_close_timeout=60)59 def execute(self, arg1):60 self.workflow_state = "Workflow Started"61 return_(arg1)62 worker = ThreadedWorkflowExecutor(WorkflowWorker(63 self.session, self.region, self.domain, self.task_list, NoActivitiesWorkflow))64 with workflow_starter(self.session, self.region, self.domain, self.task_list):65 instance = NoActivitiesWorkflow.execute(arg1="TestExecution")66 self.workflow_execution = instance.workflow_execution67 # start + stop should run the worker's Decider once68 worker.start()69 worker.stop()70 worker.join()71 time.sleep(2)72 hist = self.get_workflow_execution_history()73 self.assertEqual(len(hist), 5)74 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')75 self.assertEqual(76 hist[-2]['decisionTaskCompletedEventAttributes']['executionContext'],77 'Workflow Started')78 self.assertEqual(self.serializer.loads(79 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 'TestExecution')80 def test_one_activity(self):81 class OneActivityWorkflow(WorkflowDefinition):82 def __init__(self, workflow_execution):83 super(OneActivityWorkflow, self).__init__(workflow_execution)84 self.activities_client = BunchOfActivities()85 @execute(version='1.1', execution_start_to_close_timeout=60)86 def execute(self, arg1, arg2):87 arg_sum = yield self.activities_client.sum(arg1, arg2)88 return_(arg_sum)89 wf_worker = WorkflowWorker(90 self.session, self.region, self.domain, self.task_list, OneActivityWorkflow)91 act_worker = ThreadedActivityExecutor(ActivityWorker(92 self.session, self.region, self.domain, self.task_list, BunchOfActivities()))93 with workflow_starter(self.session, self.region, self.domain, self.task_list):94 instance = OneActivityWorkflow.execute(arg1=1, arg2=2)95 self.workflow_execution = instance.workflow_execution96 wf_worker.run_once()97 act_worker.start(1, 4)98 act_worker.stop()99 wf_worker.run_once()100 act_worker.join()101 time.sleep(1)102 hist = self.get_workflow_execution_history()103 self.assertEqual(len(hist), 11)104 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')105 self.assertEqual(self.serializer.loads(106 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 3)107 def test_one_activity_timed(self):108 class OneActivityTimedWorkflow(WorkflowDefinition):109 @execute(version='1.1', execution_start_to_close_timeout=60)110 def execute(self, arg1, arg2):111 mytime = workflow_time.time()112 yield BunchOfActivities.sum(arg1, arg2)113 return_([mytime, workflow_time.time()])114 wf_worker = WorkflowWorker(115 self.session, self.region, self.domain, self.task_list, OneActivityTimedWorkflow)116 act_worker = ActivityWorker(117 self.session, self.region, self.domain, self.task_list, BunchOfActivities())118 with workflow_starter(self.session, self.region, self.domain, self.task_list):119 instance = OneActivityTimedWorkflow.execute(arg1=1, arg2=2)120 self.workflow_execution = instance.workflow_execution121 wf_worker.run_once()122 act_worker.run_once()123 wf_worker.run_once()124 time.sleep(1)125 hist = self.get_workflow_execution_history()126 self.assertEqual(len(hist), 11)127 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')128 self.assertEqual(self.serializer.loads(129 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), [130 int(time.mktime(hist[2]['eventTimestamp'].timetuple())),131 int(time.mktime(hist[8]['eventTimestamp'].timetuple()))])132 def test_one_activity_dynamic(self):133 class OneActivityTimedWorkflow(WorkflowDefinition):134 @execute(version='1.1', execution_start_to_close_timeout=60)135 def execute(self, arg1, arg2):136 # create an activity call dynamically137 sum = flow_types.ActivityType('1.1', name='BunchOfActivities.sum')138 arg_sum = yield sum(arg1, arg2)139 return_(arg_sum)140 wf_worker = WorkflowWorker(141 self.session, self.region, self.domain, self.task_list, OneActivityTimedWorkflow)142 act_worker = ActivityWorker(143 self.session, self.region, self.domain, self.task_list, BunchOfActivities())144 with workflow_starter(self.session, self.region, self.domain, self.task_list):145 instance = OneActivityTimedWorkflow.execute(arg1=1, arg2=2)146 self.workflow_execution = instance.workflow_execution147 wf_worker.run_once()148 act_worker.run_once()149 wf_worker.run_once()150 time.sleep(1)151 hist = self.get_workflow_execution_history()152 self.assertEqual(len(hist), 11)153 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')154 self.assertEqual(self.serializer.loads(155 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 3)156 def test_one_activity_options_overrides(self):157 class OneActivityWorkflow(WorkflowDefinition):158 @execute(version='1.1', execution_start_to_close_timeout=60)159 def execute(self, arg1, arg2):160 with activity_options(start_to_close_timeout=66):161 arg_sum = yield BunchOfActivities.sum(arg1, arg2)162 return_(arg_sum)163 wf_worker = WorkflowWorker(164 self.session, self.region, self.domain, self.task_list, OneActivityWorkflow)165 act_worker = ActivityWorker(166 self.session, self.region, self.domain, self.task_list, BunchOfActivities())167 with workflow_starter(self.session, self.region, self.domain, self.task_list):168 instance = OneActivityWorkflow.execute(arg1=1, arg2=2)169 self.workflow_execution = instance.workflow_execution170 wf_worker.run_once()171 act_worker.run_once()172 wf_worker.run_once()173 time.sleep(1)174 hist = self.get_workflow_execution_history()175 self.assertEqual(len(hist), 11)176 self.assertEqual(hist[4]['activityTaskScheduledEventAttributes']['startToCloseTimeout'], '66')177 def test_one_activity_with_timer(self):178 class OneActivityWithTimerWorkflow(WorkflowDefinition):179 def __init__(self, workflow_execution):180 super(OneActivityWithTimerWorkflow, self).__init__(workflow_execution)181 self.activities_client = BunchOfActivities()182 @execute(version='1.1', execution_start_to_close_timeout=60)183 def execute(self, arg1, arg2):184 yield workflow_time.sleep(2)185 arg_sum = yield self.activities_client.sum(arg1, arg2)186 return_(arg_sum)187 wf_worker = WorkflowWorker(188 self.session, self.region, self.domain, self.task_list, OneActivityWithTimerWorkflow)189 act_worker = ActivityWorker(190 self.session, self.region, self.domain, self.task_list, BunchOfActivities())191 with workflow_starter(self.session, self.region, self.domain, self.task_list):192 instance = OneActivityWithTimerWorkflow.execute(arg1=1, arg2=2)193 self.workflow_execution = instance.workflow_execution194 wf_worker.run_once()195 wf_worker.run_once()196 act_worker.run_once()197 wf_worker.run_once()198 time.sleep(1)199 hist = self.get_workflow_execution_history()200 self.assertEqual(len(hist), 16)201 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')202 # timer specific checks203 self.assertEqual(hist[4]['eventType'], 'TimerStarted')204 self.assertEqual(hist[4]['timerStartedEventAttributes']['startToFireTimeout'], '2')205 self.assertEqual(hist[5]['eventType'], 'TimerFired')206 def test_one_activity_default_task_list(self):207 class OneActivityCustomTaskList(object):208 @activity(version='1.1', task_list='abracadabra')209 def sum(self, x, y):210 return x + y211 class OneActivityDefaultTaskListWorkflow(WorkflowDefinition):212 @execute(version='1.1', execution_start_to_close_timeout=60)213 def execute(self, arg1, arg2):214 arg_sum = yield OneActivityCustomTaskList.sum(arg1, arg2)215 return_(arg_sum)216 wf_worker = WorkflowWorker(217 self.session, self.region, self.domain, self.task_list,218 OneActivityDefaultTaskListWorkflow)219 act_worker = ThreadedActivityExecutor(ActivityWorker(220 self.session, self.region, self.domain, 'abracadabra',221 OneActivityCustomTaskList()))222 with workflow_starter(self.session, self.region, self.domain, self.task_list):223 instance = OneActivityDefaultTaskListWorkflow.execute(224 arg1=1, arg2=2)225 self.workflow_execution = instance.workflow_execution226 wf_worker.run_once()227 act_worker.start(1, 4)228 act_worker.stop()229 wf_worker.run_once()230 act_worker.join()231 time.sleep(1)232 hist = self.get_workflow_execution_history()233 self.assertEqual(len(hist), 11)234 self.assertEqual(hist[4]['activityTaskScheduledEventAttributes']235 ['taskList']['name'], 'abracadabra')236 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')237 self.assertEqual(self.serializer.loads(238 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 3)239 def test_try_except_finally_activity(self):240 class TryExceptFinallyWorkflow(WorkflowDefinition):241 @execute(version='1.1', execution_start_to_close_timeout=60)242 def execute(self, arg1, arg2):243 @coroutine244 def do_try_except():245 arg_sum = 0246 try:247 arg_sum += yield BunchOfActivities.sum(arg1, arg2)248 yield BunchOfActivities.throw()249 except ActivityTaskFailedError as err:250 if isinstance(err.cause, ValueError) \251 and str(err.cause) == 'Hello-Error':252 if err.event_id != 13 or err.activity_id != '2':253 raise RuntimeError("Test Failed")254 arg_sum += yield BunchOfActivities.sum(arg1, arg2)255 finally:256 arg_sum += yield BunchOfActivities.sum(arg1, arg2)257 return_(arg_sum)258 result = yield do_try_except()259 return_(result)260 wf_worker = WorkflowWorker(261 self.session, self.region, self.domain, self.task_list, TryExceptFinallyWorkflow)262 act_worker = ActivityWorker(263 self.session, self.region, self.domain, self.task_list, BunchOfActivities())264 with workflow_starter(self.session, self.region, self.domain, self.task_list):265 instance = TryExceptFinallyWorkflow.execute(arg1=1, arg2=2)266 self.workflow_execution = instance.workflow_execution267 for i in range(4):268 wf_worker.run_once()269 act_worker.run_once()270 wf_worker.run_once()271 time.sleep(1)272 hist = self.get_workflow_execution_history()273 self.assertEqual(len(hist), 29)274 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')275 self.assertEqual(self.serializer.loads(276 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 9)277 def test_try_except_with_timer(self):278 class TryExceptFinallyWorkflow(WorkflowDefinition):279 @execute(version='1.1', execution_start_to_close_timeout=60)280 def execute(self, arg1, arg2):281 @coroutine282 def do_try_except():283 arg_sum = 0284 try:285 arg_sum += yield BunchOfActivities.sum(arg1, arg2)286 yield BunchOfActivities.throw()287 except ActivityTaskFailedError as err:288 if isinstance(err.cause, ValueError) \289 and str(err.cause) == 'Hello-Error':290 if err.event_id != 13 or err.activity_id != '2':291 raise RuntimeError("Test Failed")292 arg_sum += yield BunchOfActivities.sum(arg1, arg2)293 yield workflow_time.sleep(1)294 return_(arg_sum)295 result = yield do_try_except()296 return_(result)297 wf_worker = WorkflowWorker(298 self.session, self.region, self.domain, self.task_list, TryExceptFinallyWorkflow)299 act_worker = ActivityWorker(300 self.session, self.region, self.domain, self.task_list, BunchOfActivities())301 with workflow_starter(self.session, self.region, self.domain, self.task_list):302 instance = TryExceptFinallyWorkflow.execute(arg1=1, arg2=2)303 self.workflow_execution = instance.workflow_execution304 for i in range(3):305 wf_worker.run_once()306 act_worker.run_once()307 # Once for the timer308 wf_worker.run_once()309 # Once for the completion310 wf_worker.run_once()311 time.sleep(1)312 hist = self.get_workflow_execution_history()313 self.assertEqual(len(hist), 28)314 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')315 self.assertEqual(self.serializer.loads(316 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 6)317 def test_two_activities(self):318 class BunchOfActivitiesWorkflow(WorkflowDefinition):319 @execute(version='1.1', execution_start_to_close_timeout=60)320 def execute(self, arg1, arg2):321 arg_sum = yield BunchOfActivities.sum(arg1, arg2)322 arg_mul = yield BunchOfActivities.mul(arg1, arg2)323 return_((arg_sum, arg_mul))324 wf_worker = WorkflowWorker(325 self.session, self.region, self.domain, self.task_list, BunchOfActivitiesWorkflow)326 act_worker = ActivityWorker(327 self.session, self.region, self.domain, self.task_list, BunchOfActivities())328 with workflow_starter(self.session, self.region, self.domain, self.task_list):329 instance = BunchOfActivitiesWorkflow.execute(arg1=1, arg2=2)330 self.workflow_execution = instance.workflow_execution331 wf_worker.run_once()332 act_worker.run_once()333 wf_worker.run_once()334 act_worker.run_once()335 wf_worker.run_once()336 time.sleep(1)337 hist = self.get_workflow_execution_history()338 self.assertEqual(len(hist), 17)339 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')340 self.assertEqual(self.serializer.loads(341 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), (3, 2))342 def test_next_page_token_activities(self):343 # process over a hundred events, so that we're clear we can work with nextPageToken344 class NextPageTokenWorkflow(WorkflowDefinition):345 @execute(version='1.1', execution_start_to_close_timeout=60)346 def execute(self, repeat, arg1):347 for i in range(repeat):348 yield BunchOfActivities.sum(i, arg1)349 return_(repeat)350 wf_worker = WorkflowWorker(351 self.session, self.region, self.domain, self.task_list, NextPageTokenWorkflow)352 act_worker = ActivityWorker(353 self.session, self.region, self.domain, self.task_list, BunchOfActivities())354 with workflow_starter(self.session, self.region, self.domain, self.task_list):355 instance = NextPageTokenWorkflow.execute(repeat=21, arg1=1)356 self.workflow_execution = instance.workflow_execution357 for i in range(21):358 wf_worker.run_once()359 act_worker.run_once()360 wf_worker.run_once() # finish off361 time.sleep(1)362 hist, token = self.get_workflow_execution_history_with_token()363 events = hist364 hist = self.get_workflow_execution_history(next_page_token=token)365 events.extend(hist)366 self.assertEqual(len(events), 131)367 self.assertEqual(events[-1]['eventType'], 'WorkflowExecutionCompleted')368 self.assertEqual(self.serializer.loads(369 events[-1]['workflowExecutionCompletedEventAttributes']['result']), 21)370 def test_all_future_activities(self):371 class AllFutureWorkflow(WorkflowDefinition):372 @execute(version='1.1', execution_start_to_close_timeout=60)373 def execute(self, arg1, arg2):374 sum_future = BunchOfActivities.sum(arg1, arg2)375 mul_future = BunchOfActivities.mul(arg1, arg2)376 result = yield sum_future, mul_future377 return_(result)378 wf_worker = WorkflowWorker(379 self.session, self.region, self.domain, self.task_list, AllFutureWorkflow)380 act_worker = ActivityWorker(381 self.session, self.region, self.domain, self.task_list, BunchOfActivities())382 with workflow_starter(self.session, self.region, self.domain, self.task_list):383 instance = AllFutureWorkflow.execute(arg1=1, arg2=2)384 self.workflow_execution = instance.workflow_execution385 wf_worker.run_once()386 act_worker.run_once()387 wf_worker.run_once()388 act_worker.run_once()389 wf_worker.run_once()390 time.sleep(1)391 hist = self.get_workflow_execution_history()392 self.assertEqual(len(hist), 17)393 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')394 self.assertEqual(self.serializer.loads(395 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), (3, 2))396 def test_any_future_activities(self):397 class SleepingActivities(object):398 @activity(version='1.2',399 schedule_to_start_timeout=60,400 start_to_close_timeout=60)401 def sleep(self, time_to_sleep):402 time.sleep(time_to_sleep)403 return time_to_sleep404 class AnyFutureWorkflow(WorkflowDefinition):405 @execute(version='1.1', execution_start_to_close_timeout=60)406 def execute(self, arg1, arg2):407 sleep1_future = SleepingActivities.sleep(arg1)408 sleep2_future = SleepingActivities.sleep(arg2)409 result = yield sleep1_future | sleep2_future410 return_(result)411 wf_worker = WorkflowWorker(412 self.session, self.region, self.domain, self.task_list, AnyFutureWorkflow)413 act_worker = ActivityWorker(414 self.session, self.region, self.domain, self.task_list, SleepingActivities())415 with workflow_starter(self.session, self.region, self.domain, self.task_list):416 instance = AnyFutureWorkflow.execute(arg1=5, arg2=1)417 self.workflow_execution = instance.workflow_execution418 wf_worker.run_once()419 act_worker.run_once()420 act_worker.run_once()421 wf_worker.run_once()422 time.sleep(1)423 hist = self.get_workflow_execution_history()424 self.assertEqual(len(hist), 14)425 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')426 self.assertTrue(self.serializer.loads(427 hist[-1]['workflowExecutionCompletedEventAttributes']['result']))428 def test_workflow_continue_as_new(self):429 class NoActivitiesWorkflow(WorkflowDefinition):430 @execute(version='1.1', execution_start_to_close_timeout=60)431 def execute(self, arg1):432 if arg1 > 0:433 arg1 -= 1434 self.execute(arg1)435 else:436 return "TestExecution"437 worker = WorkflowWorker(438 self.session, self.region, self.domain, self.task_list, NoActivitiesWorkflow)439 with workflow_starter(self.session, self.region, self.domain, self.task_list):440 instance = NoActivitiesWorkflow.execute(arg1=1)441 self.workflow_execution = instance.workflow_execution442 for i in range(2):443 worker.run_once()444 time.sleep(1)445 hist = self.get_workflow_execution_history()446 self.assertEqual(len(hist), 5)447 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionContinuedAsNew')448 new_run_id = hist[-1]['workflowExecutionContinuedAsNewEventAttributes']['newExecutionRunId']449 hist = self.get_workflow_execution_history(run_id=new_run_id)450 self.assertEqual(len(hist), 5)451 self.assertEqual(hist[-1]['eventType'], 'WorkflowExecutionCompleted')452 self.assertEqual(self.serializer.loads(453 hist[-1]['workflowExecutionCompletedEventAttributes']['result']), 'TestExecution')454 def test_subclassed_workflow(self):455 class SuperClassWorkflow(WorkflowDefinition):456 @execute(version='1.0', execution_start_to_close_timeout=60)457 def execute(self):458 pass459 class SubClassWorkflow(SuperClassWorkflow):460 @execute(version='1.0', execution_start_to_close_timeout=60)461 def execute(self):462 pass463 worker = WorkflowWorker(464 self.session, self.region, self.domain, self.task_list, SubClassWorkflow)465 with workflow_starter(self.session, self.region, self.domain, self.task_list):466 instance = SubClassWorkflow.execute()467 self.workflow_execution = instance.workflow_execution468 worker.run_once()469 time.sleep(2)470 hist = self.get_workflow_execution_history()471 self.assertEqual(len(hist), 5)472 def test_subclassed_workflow_no_exec(self):473 class SuperClassWorkflow(WorkflowDefinition):474 @execute(version='1.0', execution_start_to_close_timeout=60)475 def execute(self):476 pass477 class SubClassWorkflow(SuperClassWorkflow):478 pass479 worker = WorkflowWorker(480 self.session, self.region, self.domain, self.task_list, SubClassWorkflow)481 with workflow_starter(self.session, self.region, self.domain, self.task_list):482 instance = SubClassWorkflow.execute()483 self.workflow_execution = instance.workflow_execution484 worker.run_once()485 time.sleep(2)486 hist = self.get_workflow_execution_history()487 self.assertEqual(len(hist), 5)488 def test_subclassed_workflow_multiver(self):489 class MultiverWorkflow(WorkflowDefinition):490 @execute(version='1.0', execution_start_to_close_timeout=60)491 def start_wf(self):492 pass493 @workflow(name='MultiverWorkflow')494 class SubMultiverWorkflow(MultiverWorkflow):495 @execute(version='1.1', execution_start_to_close_timeout=60)496 def start_wf(self):497 pass498 @execute(version='1.2', execution_start_to_close_timeout=60)499 def start_wf_v2(self):500 pass501 worker = WorkflowWorker(502 self.session, self.region, self.domain, self.task_list, SubMultiverWorkflow)503 with workflow_starter(self.session, self.region, self.domain, self.task_list):504 instance = SubMultiverWorkflow.start_wf()505 self.workflow_execution = instance.workflow_execution506 worker.run_once()507 time.sleep(2)508 hist = self.get_workflow_execution_history()509 self.assertEqual(len(hist), 5)510 with workflow_starter(self.session, self.region, self.domain, self.task_list):511 instance = SubMultiverWorkflow.start_wf_v2()512 self.workflow_execution = instance.workflow_execution513 worker.run_once()514 time.sleep(2)515 hist = self.get_workflow_execution_history()516 self.assertEqual(len(hist), 5)517 self.assertEqual({'name': 'MultiverWorkflow', 'version': '1.2'},518 hist[0]519 ['workflowExecutionStartedEventAttributes']520 ['workflowType'])521if __name__ == '__main__':...
test_timeouts.py
Source:test_timeouts.py
...15 ])16 conn.poll_for_activity_task(17 "test-domain", "activity-task-list", identity="surprise")18 with freeze_time("2015-01-01 12:04:30"):19 resp = conn.get_workflow_execution_history(20 "test-domain", conn.run_id, "uid-abcd1234")21 resp["events"][-1]["eventType"].should.equal("ActivityTaskStarted")22 with freeze_time("2015-01-01 12:05:30"):23 # => Activity Task Heartbeat timeout reached!!24 resp = conn.get_workflow_execution_history(25 "test-domain", conn.run_id, "uid-abcd1234")26 resp["events"][-2]["eventType"].should.equal("ActivityTaskTimedOut")27 attrs = resp["events"][-2]["activityTaskTimedOutEventAttributes"]28 attrs["timeoutType"].should.equal("HEARTBEAT")29 # checks that event has been emitted at 12:05:00, not 12:05:3030 resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0)31 resp["events"][-1]["eventType"].should.equal("DecisionTaskScheduled")32# Decision Task Start to Close timeout33# Default value in workflow helpers: 5 mins34@mock_swf_deprecated35def test_decision_task_start_to_close_timeout():36 pass37 with freeze_time("2015-01-01 12:00:00"):38 conn = setup_workflow()39 conn.poll_for_decision_task("test-domain", "queue")["taskToken"]40 with freeze_time("2015-01-01 12:04:30"):41 resp = conn.get_workflow_execution_history(42 "test-domain", conn.run_id, "uid-abcd1234")43 event_types = [evt["eventType"] for evt in resp["events"]]44 event_types.should.equal(45 ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted"]46 )47 with freeze_time("2015-01-01 12:05:30"):48 # => Decision Task Start to Close timeout reached!!49 resp = conn.get_workflow_execution_history(50 "test-domain", conn.run_id, "uid-abcd1234")51 event_types = [evt["eventType"] for evt in resp["events"]]52 event_types.should.equal(53 ["WorkflowExecutionStarted", "DecisionTaskScheduled", "DecisionTaskStarted",54 "DecisionTaskTimedOut", "DecisionTaskScheduled"]55 )56 attrs = resp["events"][-2]["decisionTaskTimedOutEventAttributes"]57 attrs.should.equal({58 "scheduledEventId": 2, "startedEventId": 3, "timeoutType": "START_TO_CLOSE"59 })60 # checks that event has been emitted at 12:05:00, not 12:05:3061 resp["events"][-2]["eventTimestamp"].should.equal(1420113900.0)62# Workflow Execution Start to Close timeout63# Default value in workflow helpers: 2 hours64@mock_swf_deprecated65def test_workflow_execution_start_to_close_timeout():66 pass67 with freeze_time("2015-01-01 12:00:00"):68 conn = setup_workflow()69 with freeze_time("2015-01-01 13:59:30"):70 resp = conn.get_workflow_execution_history(71 "test-domain", conn.run_id, "uid-abcd1234")72 event_types = [evt["eventType"] for evt in resp["events"]]73 event_types.should.equal(74 ["WorkflowExecutionStarted", "DecisionTaskScheduled"]75 )76 with freeze_time("2015-01-01 14:00:30"):77 # => Workflow Execution Start to Close timeout reached!!78 resp = conn.get_workflow_execution_history(79 "test-domain", conn.run_id, "uid-abcd1234")80 event_types = [evt["eventType"] for evt in resp["events"]]81 event_types.should.equal(82 ["WorkflowExecutionStarted", "DecisionTaskScheduled",83 "WorkflowExecutionTimedOut"]84 )85 attrs = resp["events"][-1]["workflowExecutionTimedOutEventAttributes"]86 attrs.should.equal({87 "childPolicy": "ABANDON", "timeoutType": "START_TO_CLOSE"88 })89 # checks that event has been emitted at 14:00:00, not 14:00:30...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!