Beispiel #1
0
 def _create_job(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     return stored
Beispiel #2
0
 def test_retry_pattern(self):
     """ When we specify a retry pattern, the eta must follow it"""
     datetime_path = 'odoo.addons.connector.queue.job.datetime'
     test_pattern = {
         1:  60,
         2: 180,
         3:  10,
         5: 300,
     }
     job(retryable_error_task, retry_pattern=test_pattern)
     with mock.patch(datetime_path, autospec=True) as mock_datetime:
         mock_datetime.now.return_value = datetime(2015, 6, 1, 15, 10, 0)
         test_job = Job(func=retryable_error_task,
                        max_retries=0)
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 1)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 11, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 2)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 13, 0))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 3)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 4)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 10, 10))
         test_job.retry += 1
         test_job.postpone(self.session)
         self.assertEqual(test_job.retry, 5)
         self.assertEqual(test_job.eta, datetime(2015, 6, 1, 15, 15, 00))
Beispiel #3
0
 def test_register_jobs(self):
     job(task_a)
     job(task_b)
     self.function_model._register_jobs()
     path_a = 'odoo.addons.connector.tests.test_job.task_a'
     path_b = 'odoo.addons.connector.tests.test_job.task_b'
     self.assertTrue(self.function_model.search([('name', '=', path_a)]))
     self.assertTrue(self.function_model.search([('name', '=', path_b)]))
Beispiel #4
0
 def test_job_delay(self):
     self.cr.execute('delete from queue_job')
     job(task_a)
     job_uuid = task_a.delay(self.session, 'res.users')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)
     self.assertEqual(
         stored.uuid,
         job_uuid,
         'Incorrect returned Job UUID')
Beispiel #5
0
    def test_default_channel(self):
        self.function_model.search([]).unlink()
        job(task_a, default_channel='root.sub.subsub')
        self.assertEquals(task_a.default_channel, 'root.sub.subsub')

        self.function_model._register_jobs()

        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])

        self.assertEquals(job_func.channel, 'root.sub.subsub')
        channel = job_func.channel_id
        self.assertEquals(channel.name, 'subsub')
        self.assertEquals(channel.parent_id.name, 'sub')
        self.assertEquals(channel.parent_id.parent_id.name, 'root')
Beispiel #6
0
 def test_job_decorator(self):
     """ Test the job decorator """
     default_channel = 'channel'
     retry_pattern = {1: 5}
     partial = job(None, default_channel=default_channel,
                   retry_pattern=retry_pattern)
     self.assertEquals(partial.keywords.get('default_channel'),
                       default_channel)
     self.assertEquals(partial.keywords.get('retry_pattern'), retry_pattern)
Beispiel #7
0
 def test_retry_pattern_no_zero(self):
     """ When we specify a retry pattern without 0, uses RETRY_INTERVAL"""
     test_pattern = {
         3: 180,
     }
     job(retryable_error_task, retry_pattern=test_pattern)
     test_job = Job(func=retryable_error_task,
                    max_retries=0)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 1)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 2)
     self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 3)
     self.assertEqual(test_job._get_retry_seconds(), 180)
     test_job.retry += 1
     self.assertEqual(test_job.retry, 4)
     self.assertEqual(test_job._get_retry_seconds(), 180)
Beispiel #8
0
    def test_channel_on_job(self):
        job(task_a)
        self.function_model._register_jobs()
        path_a = '%s.%s' % (task_a.__module__, task_a.__name__)
        job_func = self.function_model.search([('name', '=', path_a)])
        self.assertEquals(job_func.channel, 'root')

        test_job = Job(func=task_a)
        storage = OdooJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root')

        channel = self.channel_model.create({'name': 'sub',
                                             'parent_id': self.root_channel.id,
                                             })
        job_func.channel_id = channel

        test_job = Job(func=task_a)
        storage = OdooJobStorage(self.session)
        storage.store(test_job)
        stored = self.job_model.search([('uuid', '=', test_job.uuid)])
        self.assertEquals(stored.channel, 'root.sub')
Beispiel #9
0
 def test_job_delay_args(self):
     self.cr.execute('delete from queue_job')
     job(dummy_task_args)
     task_a.delay(self.session, 'res.users', 'o', 'k', c='!')
     stored = self.queue_job.search([])
     self.assertEqual(len(stored), 1)