def test_scheduler_with_custom_batch_size(self): self.scheduler.stop() number_delayed_calls = 5 processed_calls_at_time = [] real_delete_calls_method = scheduler.Scheduler.delete_calls @staticmethod def delete_calls_counter(delayed_calls): real_delete_calls_method(delayed_calls) for _ in range(len(delayed_calls)): self.queue.put("item") processed_calls_at_time.append(len(delayed_calls)) scheduler.Scheduler.delete_calls = delete_calls_counter # Create 5 delayed calls for i in range(number_delayed_calls): scheduler.schedule_call(None, TARGET_METHOD_PATH, 0, **{ 'name': 'task', 'id': i }) # Start scheduler which process 2 calls at a time self.scheduler = scheduler.Scheduler(0, 1, 2) self.scheduler.start() # Wait when all of calls will be processed for _ in range(number_delayed_calls): self.queue.get() self.assertEqual([2, 2, 1], processed_calls_at_time)
def setUp(self): super(SchedulerServiceTest, self).setUp() self.timeout = timeout.Timeout(seconds=10) self.queue = queue.Queue() self.scheduler = scheduler.Scheduler(0, 1, None) self.scheduler.start() self.addCleanup(self.scheduler.stop, True) self.addCleanup(self.timeout.cancel)
def test_scheduler_multi_instance(self, method): method.side_effect = self.target_method second_scheduler = scheduler.Scheduler(1, 1, None) second_scheduler.start() self.addCleanup(second_scheduler.stop, True) scheduler.schedule_call(None, TARGET_METHOD_PATH, DELAY, **{ 'name': 'task', 'id': '321' }) calls = db_api.get_delayed_calls_to_start(get_time_delay()) self._assert_single_item(calls, target_method_name=TARGET_METHOD_PATH) self.queue.get() method.assert_called_once_with(name='task', id='321') calls = db_api.get_delayed_calls_to_start(get_time_delay()) self.assertEqual(0, len(calls))