Skip to content

Commit 17eed07

Browse files
committed
Add test
1 parent d91df7c commit 17eed07

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_job.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,23 @@ def test_create_and_cancel_job_with_serializer(self):
10891089
cancel_job(job.id, serializer=JSONSerializer, connection=self.connection)
10901090
self.assertEqual(0, len(queue.get_jobs()))
10911091

1092+
def test_canceling_job_removes_it_from_dependency_dependents_key(self):
1093+
"""Cancel child jobs and verify their IDs are removed from the parent's dependents_key."""
1094+
1095+
q = Queue('low', connection=self.connection)
1096+
parent_job = q.enqueue(fixtures.say_hello, job_id='parent_job')
1097+
child_job_1 = q.enqueue(fixtures.say_hello, depends_on=parent_job, job_id='child_job_1')
1098+
child_job_2 = q.enqueue(fixtures.say_hello, depends_on=parent_job, job_id='child_job_2')
1099+
1100+
dependents_key = parent_job.dependents_key
1101+
self.assertEqual(
1102+
{as_text(_id) for _id in self.connection.smembers(dependents_key)}, {child_job_1.id, child_job_2.id}
1103+
)
1104+
child_job_1.cancel()
1105+
self.assertEqual({as_text(_id) for _id in self.connection.smembers(dependents_key)}, {child_job_2.id})
1106+
child_job_2.cancel()
1107+
self.assertEqual({as_text(_id) for _id in self.connection.smembers(dependents_key)}, set())
1108+
10921109
def test_dependents_key_for_should_return_prefixed_job_id(self):
10931110
"""test redis key to store job dependents hash under"""
10941111
job_id = 'random'

0 commit comments

Comments
 (0)