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))
def test_postpone(self): job_a = Job(func=task_a) datetime_path = 'odoo.addons.connector.queue.job.datetime' with mock.patch(datetime_path, autospec=True) as mock_datetime: mock_datetime.now.return_value = datetime(2015, 3, 15, 16, 41, 0) job_a.postpone(result='test', seconds=60) self.assertEquals(job_a.eta, datetime(2015, 3, 15, 16, 42, 0)) self.assertEquals(job_a.result, 'test') self.assertFalse(job_a.exc_info)