test_queues_registered.py 877 B

123456789101112131415161718192021
  1. from celery import current_app
  2. from django.conf import settings
  3. from sentry.testutils.cases import TestCase
  4. class CeleryQueueRegisteredTest(TestCase):
  5. def test(self):
  6. queue_names = {q.name for q in settings.CELERY_QUEUES}
  7. missing_queue_tasks = []
  8. for task in current_app.tasks.values():
  9. # Filter out any tasks that aren't sentry specific, or don't specify `queue`.
  10. if task.name.startswith("celery.") or not hasattr(task, "queue"):
  11. continue
  12. if task.queue not in queue_names:
  13. missing_queue_tasks.append(f" - Task: {task.name}, Queue: {task.queue}")
  14. assert not missing_queue_tasks, (
  15. "Found tasks with queues that are undefined. These must be defined in "
  16. "settings.CELERY_QUEUES.\nTask Info:\n{}.".format("\n".join(missing_queue_tasks))
  17. )