def test_eager_task_does_not_call_store_result(self): @self.app.task(shared=False) def add(x, y): return x + y backend = BaseDictBackend(app=self.app) backend.store_result = Mock() add.backend = backend add.ignore_result = False self.trace(add, (2, 2), {}, eager=True) add.backend.store_result.assert_not_called()
def test_eager_task_with_setting_will_call_store_result(self): @self.app.task(shared=False) def add(x, y): return x + y backend = BaseDictBackend(app=self.app) backend.store_result = Mock() add.backend = backend add.store_eager_result = True add.ignore_result = False self.trace(add, (2, 2), {}, eager=True) add.backend.store_result.assert_called_once_with('id-1', 4, states.SUCCESS, request=ANY)
def test_execute_backend_error_acks_late(self): """direct call to execute should reject task in case of internal failure.""" tid = uuid() self.mytask.acks_late = True job = self.xRequest(id=tid, args=[4], kwargs={}) job._on_reject = Mock() job._on_ack = Mock() self.mytask.backend = BaseDictBackend(app=self.app) self.mytask.backend.mark_as_done = Mock() self.mytask.backend.mark_as_done.side_effect = Exception() self.mytask.backend.mark_as_failure = Mock() self.mytask.backend.mark_as_failure.side_effect = Exception() job.execute() assert job.acknowledged job._on_reject.assert_called_once() job._on_ack.assert_not_called()
def test_backend_error_should_report_failure(self): """check internal error is reported as failure. In case of backend error, an exception may bubble up from trace and be caught by trace_task. """ @self.app.task(shared=False) def xtask(): pass xtask.backend = BaseDictBackend(app=self.app) xtask.backend.mark_as_done = Mock() xtask.backend.mark_as_done.side_effect = Exception() xtask.backend.mark_as_failure = Mock() xtask.backend.mark_as_failure.side_effect = Exception() ret, info, _, _ = trace_task(xtask, 'uuid', (), {}, app=self.app) assert info is not None assert isinstance(ret, ExceptionInfo)
def __init__(self, *args, **kwargs): BaseDictBackend.__init__(self, *args, **kwargs) self._data = {"can-delete": {"result": "foo"}}
def test_save_group(self): b = BaseDictBackend() b._save_group = Mock() b.save_group('foofoo', 'xxx') b._save_group.assert_called_with('foofoo', 'xxx')
def __init__(self, *args, **kwargs): BaseDictBackend.__init__(self, *args, **kwargs) self._data = {'can-delete': {'result': 'foo'}}
def test_save_taskset(self): b = BaseDictBackend() b._save_taskset = Mock() b.save_taskset("foofoo", "xxx") b._save_taskset.assert_called_with("foofoo", "xxx")
def test_save_group(self): b = BaseDictBackend() b._save_group = Mock() b.save_group("foofoo", "xxx") b._save_group.assert_called_with("foofoo", "xxx")
def __init__(self, *args, **kwargs): BaseDictBackend.__init__(self, *args, **kwargs) self._db_lock = threading.Lock()
def test_forget_interface(self): b = BaseDictBackend() with self.assertRaises(NotImplementedError): b.forget("foo")