def test_start_connection_error(self): c = self.NoopConsumer(send_events=False, pool=BasePool()) c.loop.on_nth_call_do_raise(KeyError('foo'), SyntaxError('bar')) c.connection_errors = (KeyError, ) try: with self.assertRaises(SyntaxError): c.start() finally: c.timer and c.timer.stop()
def test_start_channel_error(self): c = self.NoopConsumer(task_events=False, pool=BasePool()) c.loop.on_nth_call_do_raise(KeyError('foo'), SyntaxError('bar')) c.channel_errors = (KeyError, ) try: with pytest.raises(KeyError): c.start() finally: c.timer and c.timer.stop()
def __init__(self): self.ready_queue = FastQueue() self.timer = Timer() self.app = current_app self.event_dispatcher = Mock() self.controller = WorkController() self.task_consumer = Mock() from celery.concurrency.base import BasePool self.pool = BasePool(10)
def __init__(self): self.ready_queue = FastQueue() self.ready_queue.put( TaskRequest(mytask.name, uuid(), args=(2, 2), kwargs={})) self.eta_schedule = Timer() self.app = current_app self.event_dispatcher = Mock() self.controller = WorkController() from celery.concurrency.base import BasePool self.pool = BasePool(10)
def test_start_connection_error(self): def loop_side_effect(): yield KeyError('foo') yield SyntaxError('bar') c = self.NoopConsumer(task_events=False, pool=BasePool()) c.loop.side_effect = loop_side_effect() c.connection_errors = (KeyError,) try: with pytest.raises(SyntaxError): c.start() finally: c.timer and c.timer.stop()
def __init__(self, app): self.app = app self.buffer = FastQueue() self.handle_task = self.buffer.put self.timer = Timer() self.event_dispatcher = Mock() self.controller = WorkController() self.task_consumer = Mock() from celery.concurrency.base import BasePool self.pool = BasePool(10) self.task_buckets = defaultdict(lambda: None)
def __init__(self): self.ready_queue = FastQueue() self.ready_queue.put( TaskRequest(task_name=mytask.name, task_id=gen_unique_id(), args=(2, 2), kwargs={})) self.eta_schedule = Timer() self.app = app_or_default() self.event_dispatcher = Mock() from celery.concurrency.base import BasePool self.pool = BasePool(10)
def __init__(self, app): self.app = app self.buffer = FastQueue() self.timer = Timer() self.event_dispatcher = Mock() self.controller = WorkController() self.task_consumer = Mock() self.prefetch_multiplier = 1 self.initial_prefetch_count = 1 from celery.concurrency.base import BasePool self.pool = BasePool(10) self.task_buckets = defaultdict(lambda: None) self.hub = None
def test_start_connection_error(self): class MockConsumer(MainConsumer): iterations = 0 def consume_messages(self): if not self.iterations: self.iterations = 1 raise KeyError("foo") raise SyntaxError("bar") l = MockConsumer(self.ready_queue, self.eta_schedule, self.logger, send_events=False, pool=BasePool()) l.connection_errors = (KeyError, ) self.assertRaises(SyntaxError, l.start) l.heart.stop() l.priority_timer.stop()
def test_start_connection_error(self): class MockConsumer(Consumer): iterations = 0 def loop(self, *args, **kwargs): if not self.iterations: self.iterations = 1 raise KeyError('foo') raise SyntaxError('bar') l = MockConsumer(self.buffer.put, timer=self.timer, send_events=False, pool=BasePool(), app=self.app) l.connection_errors = (KeyError, ) self.assertRaises(SyntaxError, l.start) l.timer.stop()
def test_start_channel_error(self): class MockConsumer(Consumer): iterations = 0 def loop(self, *args, **kwargs): if not self.iterations: self.iterations = 1 raise KeyError('foo') raise SyntaxError('bar') l = MockConsumer(self.ready_queue, timer=self.timer, send_events=False, pool=BasePool()) l.channel_errors = (KeyError, ) with self.assertRaises(KeyError): l.start() l.timer.stop()
def test_start_connection_error(self): class MockConsumer(BlockingConsumer): iterations = 0 def consume_messages(self): if not self.iterations: self.iterations = 1 raise KeyError('foo') raise SyntaxError('bar') l = MockConsumer(self.ready_queue, timer=self.timer, send_events=False, pool=BasePool()) l.connection_errors = (KeyError, ) with self.assertRaises(SyntaxError): l.start() l.heart.stop() l.timer.stop()
def test_start_channel_error(self): class MockConsumer(Consumer): iterations = 0 def loop(self, *args, **kwargs): if not self.iterations: self.iterations = 1 raise KeyError('foo') raise SyntaxError('bar') l = MockConsumer(self.buffer.put, timer=self.timer, send_events=False, pool=BasePool(), app=self.app) l.controller = l.app.WorkController() l.pool = l.controller.pool = Mock() l.channel_errors = (KeyError,) with self.assertRaises(KeyError): l.start() l.timer.stop()
def test_start_channel_error(self): # Regression test for AMQPChannelExceptions that can occur within the # consumer. (i.e. 404 errors) class MockConsumer(BlockingConsumer): iterations = 0 def consume_messages(self): if not self.iterations: self.iterations = 1 raise KeyError('foo') raise SyntaxError('bar') l = MockConsumer(self.ready_queue, timer=self.timer, send_events=False, pool=BasePool()) l.channel_errors = (KeyError, ) self.assertRaises(SyntaxError, l.start) l.heart.stop() l.timer.stop()
def test_start_channel_error(self): # Regression test for AMQPChannelExceptions that can occur within the # consumer. (i.e. 404 errors) class MockConsumer(MainConsumer): iterations = 0 def consume_messages(self): if not self.iterations: self.iterations = 1 raise KeyError("foo") raise SyntaxError("bar") l = MockConsumer(self.ready_queue, self.eta_schedule, self.logger, send_events=False, pool=BasePool()) l.channel_errors = (KeyError, ) self.assertRaises(SyntaxError, l.start) l.heart.stop() l.priority_timer.stop()
def __init__(self, *args, **kwargs): kwargs.setdefault('pool', BasePool(2)) kwargs.setdefault('controller', Mock()) super(_MyKombuConsumer, self).__init__(*args, **kwargs)
def test_interface_terminate_job(self): with self.assertRaises(NotImplementedError): BasePool(10).terminate_job(101)
def test_interface_on_terminate(self): p = BasePool(10) p.on_terminate()
def test_num_processes(self): self.assertEqual(BasePool(7).num_processes, 7)
def test_interface_on_apply(self): BasePool(10).on_apply()
def test_active(self): p = BasePool(10) self.assertFalse(p.active) p._state = p.RUN self.assertTrue(p.active)
def test_interface_close(self): p = BasePool(10) p.on_close = Mock() p.close() self.assertEqual(p._state, p.CLOSE) p.on_close.assert_called_with()
def test_interface_on_start(self): BasePool(10).on_start()
def test_active(self): p = BasePool(10) assert not p.active p._state = p.RUN assert p.active
def test_restart(self): p = BasePool(10) with pytest.raises(NotImplementedError): p.restart()
def test_does_not_debug(self): x = BasePool(10) x._does_debug = False x.apply_async(object)
def test_interface_close(self): p = BasePool(10) p.on_close = Mock() p.close() assert p._state == p.CLOSE p.on_close.assert_called_with()
def __init__(self, *args, **kwargs): kwargs.setdefault('pool', BasePool(2)) super(MyKombuConsumer, self).__init__(*args, **kwargs)
def test_interface_on_hard_timeout(self): self.assertIsNone(BasePool(10).on_hard_timeout(Mock()))
def test_interface_on_stop(self): BasePool(10).on_stop()
def test_interface_info(self): self.assertDictEqual(BasePool(10).info, {})
def test_interface_no_close(self): self.assertIsNone(BasePool(10).on_close())
def test_restart(self): p = BasePool(10) with self.assertRaises(NotImplementedError): p.restart()