From 3362fe2ba5c3a1f18810472f29fbbb03ea479212 Mon Sep 17 00:00:00 2001 From: Yannis Spiliopoulos Date: Thu, 30 Jun 2016 13:19:12 -0400 Subject: [PATCH] Test killing work_horse after we start monitoring --- tests/test_worker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_worker.py b/tests/test_worker.py index 8d0368f..89e0996 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -578,7 +578,8 @@ def kill_worker(pid, double_kill): time.sleep(0.5) os.kill(pid, signal.SIGTERM) -def kill_work_horse(pid): +def wait_and_kill_work_horse(pid, time_to_wait=0.0): + time.sleep(time_to_wait) os.kill(pid, signal.SIGKILL) @@ -663,18 +664,17 @@ class WorkerShutdownTestCase(TimeoutTestCase, RQTestCase): self.assertEqual(failed_q.count, 0) self.assertEqual(fooq.count, 0) w = Worker(fooq) - registry = StartedJobRegistry(connection=self.testconn) sentinel_file = '/tmp/.rq_sentinel_work_horse_death' if os.path.exists(sentinel_file): os.remove(sentinel_file) fooq.enqueue(create_file_after_timeout, sentinel_file, 100) job, queue = w.dequeue_job_and_maintain_ttl(5) w.fork_work_horse(job, queue) - p = Process(target=kill_work_horse, args=(w._horse_pid,)) + p = Process(target=wait_and_kill_work_horse, args=(w._horse_pid, 0.5)) p.start() - p.join(1) w.monitor_work_horse(job) job_status = job.get_status() + p.join(1) if os.path.exists(sentinel_file): self.assertEqual(job_status, JobStatus.FINISHED) os.remove(sentinel_file)