Browse Source

Disabled Backend: Must raise error when attempting to start chord.

Ask Solem 8 years ago
parent
commit
a7579e1298
3 changed files with 28 additions and 4 deletions
  1. 18 3
      celery/backends/base.py
  2. 4 1
      celery/utils/pytest.py
  3. 6 0
      t/unit/backends/test_base.py

+ 18 - 3
celery/backends/base.py

@@ -55,6 +55,20 @@ pending_results_t = namedtuple('pending_results_t', (
     'concrete', 'weak',
 ))
 
+E_NO_BACKEND = """
+No result backend is configured.
+Please see the documentation for more information.
+"""
+
+E_CHORD_NO_BACKEND = """
+Starting chords requires a result backend to be configured.
+
+Note that a group chained with a task is also upgraded to be a chord,
+as this pattern requires synchronization.
+
+Result backends that supports chords: Redis, Database, Memcached, and more.
+"""
+
 
 def unpickle_backend(cls, args, kwargs):
     """Return an unpickled backend."""
@@ -746,10 +760,11 @@ class DisabledBackend(BaseBackend):
     def store_result(self, *args, **kwargs):
         pass
 
+    def apply_chord(self, *args, **kwargs):
+        raise NotImplementedError(E_CHORD_NO_BACKEND.strip())
+
     def _is_disabled(self, *args, **kwargs):
-        raise NotImplementedError(
-            'No result backend configured.  '
-            'Please see the documentation for more information.')
+        raise NotImplementedError(E_NO_BACKEND.strip())
 
     def as_uri(self, *args, **kwargs):
         return 'disabled://'

+ 4 - 1
celery/utils/pytest.py

@@ -84,6 +84,9 @@ def TestApp(name=None, set_as_current=False, log=UnitLogging,
 def app(request):
     """Fixture creating a Celery application instance."""
     from celery import _state
+    mark = request.node.get_marker('celery')
+    mark = mark and mark.kwargs or {}
+
     prev_current_app = current_app()
     prev_default_app = _state.default_app
     prev_finalizers = set(_state._on_app_finalizers)
@@ -96,7 +99,7 @@ def app(request):
         current_app = trap
     _state._tls = NonTLS()
 
-    test_app = TestApp(set_as_current=False)
+    test_app = TestApp(set_as_current=False, backend=mark.get('backend'))
     is_not_contained = any([
         not getattr(request.module, 'app_contained', True),
         not getattr(request.cls, 'app_contained', True),

+ 6 - 0
t/unit/backends/test_base.py

@@ -588,6 +588,12 @@ class test_DisabledBackend:
     def test_as_uri(self):
         assert DisabledBackend(self.app).as_uri() == 'disabled://'
 
+    @pytest.mark.celery(backend='disabled')
+    def test_chord_raises_error(self):
+        from celery import chord
+        with pytest.raises(NotImplementedError):
+            chord(self.add.s(i, i) for i in range(10))(self.add.s([2]))
+
 
 class test_as_uri: