def test_execute_plan_with_watchers(self, patched_multiprocessing): watch_func = mock.MagicMock() plan = Plan(description="Test", sleep_time=0, watch_func=watch_func) previous_stack = None for i in range(5): overrides = {} if previous_stack: overrides["requires"] = [previous_stack.fqn] stack = Stack( definition=generate_definition("vpc", i, **overrides), context=self.context, ) previous_stack = stack plan.add( stack=stack, run_func=self._run_func, requires=stack.requires, ) plan.execute() self.assertEqual(self.count, 9) self.assertEqual(len(plan.list_skipped()), 1) self.assertEqual(patched_multiprocessing.Process().start.call_count, 5) # verify we terminate the process when the stack is finished and also # redundantly terminate the process after execution self.assertEqual( patched_multiprocessing.Process().terminate.call_count, 10)
def test_execute_plan_with_watchers(self, patched_multiprocessing): watch_func = mock.MagicMock() plan = Plan(description='Test', sleep_time=0, watch_func=watch_func) previous_stack = None for i in range(5): overrides = {} if previous_stack: overrides['requires'] = [previous_stack.fqn] stack = Stack( definition=generate_definition('vpc', i, **overrides), context=self.context, ) previous_stack = stack plan.add( stack=stack, run_func=self._run_func, requires=stack.requires, ) plan.execute() self.assertEqual(self.count, 9) self.assertEqual(len(plan.list_skipped()), 1) self.assertEqual(patched_multiprocessing.Process().start.call_count, 5) # verify we terminate the process when the stack is finished and also # redundantly terminate the process after execution self.assertEqual( patched_multiprocessing.Process().terminate.call_count, 10)
def test_step_must_return_status(self): plan = Plan(description="Test", sleep_time=0) stack = Stack(definition=generate_definition("vpc", 1), context=mock.MagicMock()) plan.add( stack=stack, run_func=lambda x, **kwargs: (x), ) with self.assertRaises(ValueError): plan.execute()
def test_step_must_return_status(self): plan = Plan(description='Test', sleep_time=0) stack = Stack(definition=generate_definition('vpc', 1), context=mock.MagicMock()) plan.add( stack=stack, run_func=lambda x, **kwargs: (x), ) with self.assertRaises(ValueError): plan.execute()
def test_execute_plan_wait_func_not_called_if_complete(self): wait_func = mock.MagicMock() plan = Plan(description="Test", wait_func=wait_func) def run_func(*args, **kwargs): return COMPLETE for i in range(2): stack = Stack(definition=generate_definition("vpc", i), context=self.context) plan.add(stack=stack, run_func=run_func, requires=stack.requires) plan.execute() self.assertEqual(wait_func.call_count, 0)
def test_execute_plan(self): plan = Plan(description="Test", sleep_time=0) previous_stack = None for i in range(5): overrides = {} if previous_stack: overrides["requires"] = [previous_stack.fqn] stack = Stack(definition=generate_definition("vpc", i, **overrides), context=self.context) previous_stack = stack plan.add(stack=stack, run_func=self._run_func, requires=stack.requires) plan.execute() self.assertEqual(self.count, 9) self.assertEqual(len(plan.list_skipped()), 1)
def test_execute_plan_wait_func_not_called_if_complete(self): wait_func = mock.MagicMock() plan = Plan(description="Test", wait_func=wait_func) def run_func(*args, **kwargs): return COMPLETE for i in range(2): stack = Stack(definition=generate_definition("vpc", i), context=self.context) plan.add( stack=stack, run_func=run_func, requires=stack.requires, ) plan.execute() self.assertEqual(wait_func.call_count, 0)
def test_execute_plan(self): plan = Plan(description="Test", sleep_time=0) previous_stack = None for i in range(5): overrides = {} if previous_stack: overrides["requires"] = [previous_stack.fqn] stack = Stack( definition=generate_definition("vpc", i, **overrides), context=self.context, ) previous_stack = stack plan.add( stack=stack, run_func=self._run_func, requires=stack.requires, ) plan.execute() self.assertEqual(self.count, 9) self.assertEqual(len(plan.list_skipped()), 1)
def test_reset_plan(self): plan = Plan(description='Test', sleep_time=0) previous_stack = None for i in range(5): overrides = {} if previous_stack: overrides['requires'] = [previous_stack.fqn] stack = Stack( definition=generate_definition('vpc', i, **overrides), context=self.context, ) previous_stack = stack plan.add( stack=stack, run_func=self._run_func, requires=stack.requires, ) plan.execute() self.assertEqual(self.count, 9) self.assertEqual(len(plan.list_skipped()), 1) plan.reset() self.assertEqual(len(plan.list_pending()), len(plan))