From 1349e90ba2094de6d42a0cc75dfaf36b1fa2cd4f Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 14 Oct 2015 21:22:36 +0100 Subject: [PATCH] test docstrings, and sentinel test --- tests/test_worker.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_worker.py b/tests/test_worker.py index f3032ea..4528ae1 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -11,7 +11,7 @@ from multiprocessing import Process from tests import RQTestCase, slow 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 rq import get_failed_queue, Queue, SimpleWorker, Worker @@ -496,6 +496,7 @@ class TestWorkerShutdown(RQTestCase): @slow def test_idle_worker_warm_shutdown(self): + """worker with no ongoing job receiving single SIGTERM signal and shutting down""" w = Worker('foo') self.assertFalse(w._stop_requested) p = Process(target=kill_worker, args=(os.getpid(), False)) @@ -508,23 +509,29 @@ class TestWorkerShutdown(RQTestCase): @slow 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') 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) p = Process(target=kill_worker, args=(os.getpid(), False)) p.start() w.work() - p.join(1) + p.join(2) self.assertTrue(w._stop_requested) + self.assertTrue(os.path.exists(sentinel_file)) @slow def test_working_worker_cold_shutdown(self): + """worker with an ongoing job receiving double SIGTERM signal and shutting down immediately""" fooq = Queue('foo') 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) p = Process(target=kill_worker, args=(os.getpid(), True)) p.start() @@ -533,4 +540,5 @@ class TestWorkerShutdown(RQTestCase): p.join(1) self.assertTrue(w._stop_requested) + self.assertFalse(os.path.exists(sentinel_file))