Browse Source

Fixes hanging test (the joys of MagicMock)

Ask Solem 8 years ago
parent
commit
895c04cbf5
3 changed files with 11 additions and 3 deletions
  1. 1 1
      celery/app/task.py
  2. 6 2
      celery/canvas.py
  3. 4 0
      t/unit/tasks/test_tasks.py

+ 1 - 1
celery/app/task.py

@@ -825,7 +825,7 @@ class Task(object):
 
         if self.request.chain:
             for t in self.request.chain:
-                sig |= signature(t)
+                sig |= signature(t, app=self.app)
 
         sig.freeze(self.request.id,
                    group_id=self.request.group,

+ 6 - 2
celery/canvas.py

@@ -61,7 +61,7 @@ def _shorten_names(task_name, s):
     # This is used by repr(), to remove repeating module names.
 
     # extract the module part of the task name
-    module = task_name.rpartition('.')[0] + '.'
+    module = str(task_name).rpartition('.')[0] + '.'
     # find the first occurance of the module name in the string.
     index = s.find(module)
     if index >= 0:
@@ -1285,8 +1285,12 @@ class chord(Signature):
         # but the body may actually be a chain,
         # so find the first result without a parent
         node = bodyres
+        seen = set()
         while node:
-            if not node.parent:
+            if node.id in seen:
+                raise RuntimeError('Recursive result parents')
+            seen.add(node.id)
+            if node.parent is None:
                 node.parent = header_result
                 break
             node = node.parent

+ 4 - 0
t/unit/tasks/test_tasks.py

@@ -429,8 +429,12 @@ class test_tasks(TasksCase):
         self.mytask.request.errbacks = 'errbacks'
 
         class JsonMagicMock(MagicMock):
+            parent = None
+
             def __json__(self):
                 return 'whatever'
+            def reprcall(self, *args, **kwargs):
+                return 'whatever2'
 
         mocked_signature = JsonMagicMock(name='s')
         accumulate_mock = JsonMagicMock(name='accumulate', s=mocked_signature)