|
|
@@ -1,4 +1,6 @@
|
|
|
from django_rq import get_queue
|
|
|
+from django_rq.workers import get_worker
|
|
|
+from rq import SimpleWorker
|
|
|
|
|
|
__all__ = (
|
|
|
'RQQueueTestMixin',
|
|
|
@@ -16,6 +18,19 @@ class RQQueueTestMixin:
|
|
|
for queue_name in cls.rq_queue_names:
|
|
|
get_queue(queue_name).connection.flushall()
|
|
|
|
|
|
+ def run_rq_jobs(self, *queue_names, burst=True):
|
|
|
+ """
|
|
|
+ Process queued RQ jobs synchronously for the given queue(s) (defaulting to 'default').
|
|
|
+
|
|
|
+ Uses a non-forking SimpleWorker: the default RQ worker forks a work horse which would
|
|
|
+ inherit the test's open database connection. Two processes sharing one connection
|
|
|
+ corrupts it — on an SSL-encrypted connection this surfaces as "bad record mac" and
|
|
|
+ closes the connection for every subsequent test. SimpleWorker runs jobs in-process,
|
|
|
+ so the connection is never shared.
|
|
|
+ """
|
|
|
+ worker = get_worker(*(queue_names or ('default',)), worker_class=SimpleWorker)
|
|
|
+ worker.work(burst=burst)
|
|
|
+
|
|
|
def setUp(self):
|
|
|
super().setUp()
|
|
|
|