test docstrings, and sentinel test

main
Samuel Colvin 9 years ago
parent fa48751fed
commit 1349e90ba2

@ -11,7 +11,7 @@ from multiprocessing import Process
from tests import RQTestCase, slow from tests import RQTestCase, slow
from tests.fixtures import (create_file, create_file_after_timeout, from tests.fixtures import (create_file, create_file_after_timeout,
div_by_zero, do_nothing, say_hello, say_pid, long_running_job) div_by_zero, do_nothing, say_hello, say_pid)
from tests.helpers import strip_microseconds from tests.helpers import strip_microseconds
from rq import get_failed_queue, Queue, SimpleWorker, Worker from rq import get_failed_queue, Queue, SimpleWorker, Worker
@ -496,6 +496,7 @@ class TestWorkerShutdown(RQTestCase):
@slow @slow
def test_idle_worker_warm_shutdown(self): def test_idle_worker_warm_shutdown(self):
"""worker with no ongoing job receiving single SIGTERM signal and shutting down"""
w = Worker('foo') w = Worker('foo')
self.assertFalse(w._stop_requested) self.assertFalse(w._stop_requested)
p = Process(target=kill_worker, args=(os.getpid(), False)) p = Process(target=kill_worker, args=(os.getpid(), False))
@ -508,23 +509,29 @@ class TestWorkerShutdown(RQTestCase):
@slow @slow
def test_working_worker_warm_shutdown(self): def test_working_worker_warm_shutdown(self):
"""worker with an ongoing job receiving single SIGTERM signal, allowing job to finish then shutting down"""
fooq = Queue('foo') fooq = Queue('foo')
w = Worker(fooq) w = Worker(fooq)
fooq.enqueue(long_running_job, 2)
sentinel_file = '/tmp/.rq_sentinel_warm'
fooq.enqueue(create_file_after_timeout, sentinel_file, 2)
self.assertFalse(w._stop_requested) self.assertFalse(w._stop_requested)
p = Process(target=kill_worker, args=(os.getpid(), False)) p = Process(target=kill_worker, args=(os.getpid(), False))
p.start() p.start()
w.work() w.work()
p.join(1) p.join(2)
self.assertTrue(w._stop_requested) self.assertTrue(w._stop_requested)
self.assertTrue(os.path.exists(sentinel_file))
@slow @slow
def test_working_worker_cold_shutdown(self): def test_working_worker_cold_shutdown(self):
"""worker with an ongoing job receiving double SIGTERM signal and shutting down immediately"""
fooq = Queue('foo') fooq = Queue('foo')
w = Worker(fooq) w = Worker(fooq)
fooq.enqueue(long_running_job, 10) sentinel_file = '/tmp/.rq_sentinel_cold'
fooq.enqueue(create_file_after_timeout, sentinel_file, 2)
self.assertFalse(w._stop_requested) self.assertFalse(w._stop_requested)
p = Process(target=kill_worker, args=(os.getpid(), True)) p = Process(target=kill_worker, args=(os.getpid(), True))
p.start() p.start()
@ -533,4 +540,5 @@ class TestWorkerShutdown(RQTestCase):
p.join(1) p.join(1)
self.assertTrue(w._stop_requested) self.assertTrue(w._stop_requested)
self.assertFalse(os.path.exists(sentinel_file))

Loading…
Cancel
Save