|
|
|
@ -13,7 +13,6 @@ import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
import mock
|
|
|
|
|
from mock import Mock
|
|
|
|
|
|
|
|
|
@ -31,7 +30,7 @@ from rq.job import Job, JobStatus
|
|
|
|
|
from rq.registry import StartedJobRegistry
|
|
|
|
|
from rq.suspension import resume, suspend
|
|
|
|
|
from rq.utils import utcnow
|
|
|
|
|
from rq.worker import HerokuWorker
|
|
|
|
|
from rq.worker import HerokuWorker, WorkerStatus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomJob(Job):
|
|
|
|
@ -43,6 +42,7 @@ class CustomQueue(Queue):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestWorker(RQTestCase):
|
|
|
|
|
|
|
|
|
|
def test_create_worker(self):
|
|
|
|
|
"""Worker creation using various inputs."""
|
|
|
|
|
|
|
|
|
@ -105,10 +105,23 @@ class TestWorker(RQTestCase):
|
|
|
|
|
'Expected at least some work done.'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_find_by_key(self):
|
|
|
|
|
"""Worker.find_by_key restores queues, state and job_id."""
|
|
|
|
|
queues = [Queue('foo'), Queue('bar')]
|
|
|
|
|
w = Worker(queues)
|
|
|
|
|
w.register_death()
|
|
|
|
|
w.register_birth()
|
|
|
|
|
w.set_state(WorkerStatus.STARTED)
|
|
|
|
|
worker = Worker.find_by_key(w.key)
|
|
|
|
|
self.assertEqual(worker.queues, queues)
|
|
|
|
|
self.assertEqual(worker.get_state(), WorkerStatus.STARTED)
|
|
|
|
|
self.assertEqual(worker._job_id, None)
|
|
|
|
|
w.register_death()
|
|
|
|
|
|
|
|
|
|
def test_worker_ttl(self):
|
|
|
|
|
"""Worker ttl."""
|
|
|
|
|
w = Worker([])
|
|
|
|
|
w.register_birth() # ugly: our test should only call public APIs
|
|
|
|
|
w.register_birth()
|
|
|
|
|
[worker_key] = self.testconn.smembers(Worker.redis_workers_keys)
|
|
|
|
|
self.assertIsNotNone(self.testconn.ttl(worker_key))
|
|
|
|
|
w.register_death()
|
|
|
|
|