def test_reject_delay(self): """Rejected task is requeued after delay""" tasks.rejecting_task_with_delay() with run_worker() as worker: worker.expect('Task is rejected') assert len_queue("kuyruk") == 0 worker.expect('Task is rejected') assert len_queue("kuyruk") == 1
def test_reject(self): """Rejected task is requeued""" tasks.rejecting_task() with run_kuyruk() as worker: worker.expect('Task is rejected') worker.expect('Task is rejected') assert len_queue("kuyruk") == 1
def test_reject(self): """Rejected task is requeued""" tasks.rejecting_task() with run_worker() as worker: worker.expect('Task is rejected') worker.expect('Task is rejected') assert len_queue("kuyruk") == 1
def test_retry(self): """Errored task is retried""" tasks.retry_task() with run_kuyruk() as worker: worker.expect('ZeroDivisionError') worker.expect('ZeroDivisionError') assert len_queue("kuyruk") == 0
def test_worker_sigquit(self): """Worker drops the task on SIGQUIT""" tasks.loop_forever() with run_worker() as worker: worker.expect('looping forever') worker.send_signal(signal.SIGUSR2) worker.expect('Dropping current task') assert len_queue("kuyruk") == 0, worker.get_output()
def test_another_queue(self): """Task is run on another queue""" delete_queue('another_queue') tasks.echo_another('hello another') assert len_queue('another_queue') == 1 with run_worker(queue='another_queue') as worker: worker.expect('Consumer started') worker.expect('hello another') worker.expect('Task is processed')
def test_invalid_json(self): """Message is dropped when JSON is not valid""" with run_worker() as worker: worker.expect('Consumer started') with new_instance().channel() as ch: msg = amqp.Message(body='foo') ch.basic_publish(msg, exchange='', routing_key='kuyruk') worker.expect('Cannot decode message') self.assertEqual(len_queue('kuyruk'), 0)
def test_worker_sigquit(self): """Ack current message and exit""" tasks.loop_forever() with run_kuyruk() as worker: worker.expect('looping forever') pid = get_pid('kuyruk: worker') os.kill(pid, signal.SIGUSR2) worker.expect('Dropping current task') assert len_queue("kuyruk") == 0, worker.get_output()
def test_sigint(self): """Worker shuts down gracefully on SIGINT""" tasks.just_sleep(1) tasks.just_sleep(1) with run_worker(terminate=False) as worker: worker.expect('Processing task') worker.send_signal(signal.SIGINT) worker.expect('Task is successful') worker.expect_exit(0) assert len_queue("kuyruk") == 1, worker.get_output()
def test_invalid_task_path(self): """Message is dropped when task cannot be imported""" with run_worker() as worker: worker.expect('Consumer started') with new_instance().channel() as ch: desc = {'module': 'kuyruk', 'function': 'foo'} body = json.dumps(desc) msg = amqp.Message(body=body) ch.basic_publish(msg, exchange='', routing_key='kuyruk') worker.expect('Cannot import task') self.assertEqual(len_queue('kuyruk'), 0)
def test_exception(self): """Errored task message is discarded""" tasks.raise_exception() with run_worker() as worker: worker.expect('ZeroDivisionError') assert len_queue("kuyruk") == 0
def test_exception(self): """Errored task message is discarded""" tasks.raise_exception() with run_kuyruk() as worker: worker.expect('ZeroDivisionError') assert len_queue("kuyruk") == 0