From 3af0e95ce5a0314fa8d95b60785e6cf2979e9d6b Mon Sep 17 00:00:00 2001 From: glaslos Date: Thu, 29 Jan 2015 14:19:50 +0100 Subject: [PATCH] adding two tests to ensure ttl behaviour --- tests/fixtures.py | 5 +++-- tests/test_job.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index a0e8eba..4271373 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -85,5 +85,6 @@ with Connection(): return x + y -def long_running_job(): - time.sleep(10) +def long_running_job(timeout=10): + time.sleep(timeout) + return 'Done sleeping...' diff --git a/tests/test_job.py b/tests/test_job.py index 34859a7..1684315 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -12,7 +12,7 @@ from rq.utils import utcformat from tests import RQTestCase from tests.fixtures import (access_self, CallableObject, Number, say_hello, - some_calculation) + some_calculation, long_running_job) from tests.helpers import strip_microseconds try: @@ -313,6 +313,22 @@ class TestJob(RQTestCase): job.save() self.assertEqual(job.get_ttl(), None) + def test_ttl_via_enqueue(self): + ttl = 1 + queue = Queue(connection=self.testconn) + job = queue.enqueue(say_hello, ttl=ttl) + self.assertEqual(job.get_ttl(), ttl) + + def test_expire_during_execution(self): + """Test what happens when job expires during execution""" + ttl = 2 + queue = Queue(connection=self.testconn) + job = queue.enqueue(long_running_job, args=(4,), ttl=ttl) + self.assertEqual(job.get_ttl(), ttl) + job.perform() + self.assertFalse(job.exists(job.id)) + self.assertEqual(job.result, 'Done sleeping...') + def test_cleanup(self): """Test that jobs and results are expired properly.""" job = Job.create(func=say_hello)