예제 #1
0
 def test_retry_on_exception(self):
     """ calling _retry() should call try until the task succeeds.  """
     task_config = TaskConfig(
         {"options": {"retries": 5, "retry_interval": 1, "retry_interval_add": 1}}
     )
     task = BaseTask(self.project_config, task_config, self.org_config)
     task._try = mock.Mock(side_effect=[Exception, Exception, 1])
     task._retry()
     self.assertEqual(task._try.call_count, 3)
예제 #2
0
 def test_retry_on_exception(self):
     """ calling _retry() should call try until the task succeeds.  """
     task_config = TaskConfig(
         {"options": {"retries": 5, "retry_interval": 1, "retry_interval_add": 1}}
     )
     task = BaseTask(self.project_config, task_config, self.org_config)
     task._try = mock.Mock(side_effect=[Exception, Exception, 1])
     task._retry()
     self.assertEqual(task._try.call_count, 3)
예제 #3
0
    def test_poll(self):
        task = BaseTask(self.project_config, self.task_config, self.org_config)

        task.i = 0

        def mimic_polling():
            task.i += 1
            if task.i > 3:
                task.poll_complete = True

        task._poll_action = mock.Mock(side_effect=mimic_polling)
        task._poll()
        self.assertEqual(4, task.poll_count)
        self.assertEqual(1, task.poll_interval_level)
        self.assertEqual(2, task.poll_interval_s)
예제 #4
0
 def test_init_options__project_config_integer(self):
     self.project_config.config["foo"] = {"bar": 32}
     self.task_config.config["options"] = {
         "test_option": "$project_config.foo__bar"
     }
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     self.assertEqual("32", task.options["test_option"])
예제 #5
0
 def test_init_options__project_config_substitution__substring(self):
     self.project_config.config["foo"] = {"bar": "baz"}
     self.task_config.config["options"] = {
         "test_option": "before $project_config.foo__bar after"
     }
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     self.assertEqual("before baz after", task.options["test_option"])
예제 #6
0
 def _create_task(self, task_config=None, org_config=None):
     if not task_config:
         task_config = {}
     if not org_config:
         org_config = {}
     task = BaseTask(
         project_config=self.project_config,
         task_config=TaskConfig(task_config),
         org_config=DummyOrgConfig(org_config),
     )
     return task
예제 #7
0
 def test_init_options__not_shared(self):
     self.project_config.config["foo"] = {"bar": "baz"}
     self.task_config.config["options"] = {}
     task1 = BaseTask(self.project_config, self.task_config,
                      self.org_config)
     self.task_config.options["test_option"] = "baz"
     task1._init_options({})
     self.task_config.options["test_option"] = "jazz"
     task2 = BaseTask(self.project_config, self.task_config,
                      self.org_config)
     task2._init_options({})
     self.assertEqual("baz", task1.options["test_option"])
     self.assertEqual("jazz", task2.options["test_option"])
예제 #8
0
 def test_retry_until_too_many(self):
     """ calling _retry should call try until the retry count is exhausted. """
     task_config = TaskConfig(
         {"options": {"retries": 5, "retry_interval": 1, "retry_interval_add": 1}}
     )
     task = BaseTask(self.project_config, task_config, self.org_config)
     task._try = mock.Mock(
         side_effect=[
             RuntimeError(5),
             RuntimeError(4),
             RuntimeError(3),
             RuntimeError(2),
             RuntimeError(1),
             RuntimeError(0),
         ]
     )
     with self.assertRaises(RuntimeError) as cm:
         task._retry()
     self.assertEqual(cm.exception.args[0], 0)  # assert it was the final call
     self.assertEqual(task._try.call_count, 6)
     self.assertEqual(task.options["retry_interval"], 6)
예제 #9
0
 def test_retry_until_too_many(self):
     """ calling _retry should call try until the retry count is exhausted. """
     task_config = TaskConfig(
         {"options": {"retries": 5, "retry_interval": 1, "retry_interval_add": 1}}
     )
     task = BaseTask(self.project_config, task_config, self.org_config)
     task._try = mock.Mock(
         side_effect=[
             RuntimeError(5),
             RuntimeError(4),
             RuntimeError(3),
             RuntimeError(2),
             RuntimeError(1),
             RuntimeError(0),
         ]
     )
     with self.assertRaises(RuntimeError) as cm:
         task._retry()
     self.assertEqual(cm.exception.args[0], 0)  # assert it was the final call
     self.assertEqual(task._try.call_count, 6)
     self.assertEqual(task.options["retry_interval"], 6)
예제 #10
0
    def test_poll(self):
        task = BaseTask(self.project_config, self.task_config, self.org_config)

        task.i = 0

        def mimic_polling():
            task.i += 1
            if task.i > 3:
                task.poll_complete = True

        task._poll_action = mock.Mock(side_effect=mimic_polling)
        task._poll()
        self.assertEqual(4, task.poll_count)
        self.assertEqual(1, task.poll_interval_level)
        self.assertEqual(2, task.poll_interval_s)
예제 #11
0
 def test_poll_action(self):
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     with self.assertRaises(NotImplementedError):
         task._poll_action()
예제 #12
0
 def test_is_retry_valid(self):
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     self.assertTrue(task._is_retry_valid(None))
예제 #13
0
 def test_is_retry_valid(self):
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     self.assertTrue(task._is_retry_valid(None))
예제 #14
0
 def test_run_task(self):
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     with self.assertRaises(NotImplementedError):
         task()
예제 #15
0
 def test_option_overrides(self):
     task = BaseTask(
         self.project_config, self.task_config, self.org_config, foo="bar"
     )
     self.assertEqual("bar", task.options["foo"])
예제 #16
0
    def test_task_is_callable(self):
        """ BaseTask is Callable """
        task = BaseTask(self.project_config, self.task_config, self.org_config)

        self.assertIsInstance(task, collections.abc.Callable)
예제 #17
0
 def test_poll_action(self):
     task = BaseTask(self.project_config, self.task_config, self.org_config)
     with self.assertRaises(NotImplementedError):
         task._poll_action()