Esempio n. 1
0
 def test_fast_trace_task(self):
     from celery.app import trace
     setup_worker_optimizations(self.app)
     self.assertIs(trace.trace_task_ret, trace._fast_trace_task)
     tid = uuid()
     message = TaskMessage(self.mytask.name, tid, args=[4])
     assert len(message.payload) == 3
     try:
         self.mytask.__trace__ = build_tracer(
             self.mytask.name, self.mytask, self.app.loader, 'test',
             app=self.app,
         )
         failed, res, runtime = trace.trace_task_ret(
             self.mytask.name, tid, message.headers, message.body,
             message.content_type, message.content_encoding)
         self.assertFalse(failed)
         self.assertEqual(res, repr(4 ** 4))
         self.assertTrue(runtime)
         self.assertIsInstance(runtime, numbers.Real)
     finally:
         reset_worker_optimizations()
         self.assertIs(trace.trace_task_ret, trace._trace_task_ret)
     delattr(self.mytask, '__trace__')
     failed, res, runtime = trace.trace_task_ret(
         self.mytask.name, tid, message.headers, message.body,
         message.content_type, message.content_encoding, app=self.app,
     )
     self.assertFalse(failed)
     self.assertEqual(res, repr(4 ** 4))
     self.assertTrue(runtime)
     self.assertIsInstance(runtime, numbers.Real)
Esempio n. 2
0
 def test_fast_trace_task(self):
     from celery.app import trace
     setup_worker_optimizations(self.app)
     assert trace.trace_task_ret is trace._fast_trace_task
     tid = uuid()
     message = self.TaskMessage(self.mytask.name, tid, args=[4])
     assert len(message.payload) == 3
     try:
         self.mytask.__trace__ = build_tracer(
             self.mytask.name, self.mytask, self.app.loader, 'test',
             app=self.app,
         )
         failed, res, runtime = trace.trace_task_ret(
             self.mytask.name, tid, message.headers, message.body,
             message.content_type, message.content_encoding)
         assert not failed
         assert res == repr(4 ** 4)
         assert runtime is not None
         assert isinstance(runtime, numbers.Real)
     finally:
         reset_worker_optimizations()
         assert trace.trace_task_ret is trace._trace_task_ret
     delattr(self.mytask, '__trace__')
     failed, res, runtime = trace.trace_task_ret(
         self.mytask.name, tid, message.headers, message.body,
         message.content_type, message.content_encoding, app=self.app,
     )
     assert not failed
     assert res == repr(4 ** 4)
     assert runtime is not None
     assert isinstance(runtime, numbers.Real)
 def test_fast_trace_task(self):
     from celery.app import trace
     setup_worker_optimizations(self.app)
     self.assertIs(trace.trace_task_ret, trace._fast_trace_task)
     try:
         self.mytask.__trace__ = build_tracer(
             self.mytask.name,
             self.mytask,
             self.app.loader,
             'test',
             app=self.app,
         )
         res = trace.trace_task_ret(self.mytask.name, uuid(), [4], {})
         self.assertEqual(res, 4**4)
     finally:
         reset_worker_optimizations()
         self.assertIs(trace.trace_task_ret, trace._trace_task_ret)
     delattr(self.mytask, '__trace__')
     res = trace.trace_task_ret(
         self.mytask.name,
         uuid(),
         [4],
         {},
         app=self.app,
     )
     self.assertEqual(res, 4**4)
Esempio n. 4
0
 def test_fast_trace_task(self):
     from celery.app import trace
     setup_worker_optimizations(self.app)
     self.assertIs(trace.trace_task_ret, trace._fast_trace_task)
     tid = uuid()
     message = TaskMessage(self.mytask.name, tid, args=[4])
     assert len(message.payload) == 3
     try:
         self.mytask.__trace__ = build_tracer(
             self.mytask.name, self.mytask, self.app.loader, 'test',
             app=self.app,
         )
         failed, res, runtime = trace.trace_task_ret(
             self.mytask.name, tid, message.headers, message.body,
             message.content_type, message.content_encoding)
         self.assertFalse(failed)
         self.assertEqual(res, repr(4 ** 4))
         self.assertIsNotNone(runtime)
         self.assertIsInstance(runtime, numbers.Real)
     finally:
         reset_worker_optimizations()
         self.assertIs(trace.trace_task_ret, trace._trace_task_ret)
     delattr(self.mytask, '__trace__')
     failed, res, runtime = trace.trace_task_ret(
         self.mytask.name, tid, message.headers, message.body,
         message.content_type, message.content_encoding, app=self.app,
     )
     self.assertFalse(failed)
     self.assertEqual(res, repr(4 ** 4))
     self.assertIsNotNone(runtime)
     self.assertIsInstance(runtime, numbers.Real)
Esempio n. 5
0
 def test_fast_trace_task(self):
     from celery.app import trace
     setup_worker_optimizations(self.app)
     assert trace.trace_task_ret is trace._fast_trace_task
     tid = uuid()
     message = self.TaskMessage(self.mytask.name, tid, args=[4])
     assert len(message.payload) == 3
     try:
         self.mytask.__trace__ = build_tracer(
             self.mytask.name, self.mytask, self.app.loader, 'test',
             app=self.app,
         )
         failed, res, runtime = trace.trace_task_ret(
             self.mytask.name, tid, message.headers, message.body,
             message.content_type, message.content_encoding)
         assert not failed
         assert res == repr(4 ** 4)
         assert runtime is not None
         assert isinstance(runtime, numbers.Real)
     finally:
         reset_worker_optimizations()
         assert trace.trace_task_ret is trace._trace_task_ret
     delattr(self.mytask, '__trace__')
     failed, res, runtime = trace.trace_task_ret(
         self.mytask.name, tid, message.headers, message.body,
         message.content_type, message.content_encoding, app=self.app,
     )
     assert not failed
     assert res == repr(4 ** 4)
     assert runtime is not None
     assert isinstance(runtime, numbers.Real)
Esempio n. 6
0
 def test_trace_task_ret__no_content_type(self):
     trace_task_ret(
         self.add.name,
         'id1',
         {},
         ((2, 2), {}, {}),
         None,
         None,
         app=self.app,
     )
Esempio n. 7
0
    def test_fast_trace_task(self):
        from celery.app import trace

        setup_worker_optimizations(self.app)
        self.assertIs(trace.trace_task_ret, trace._fast_trace_task)
        try:
            self.mytask.__trace__ = build_tracer(self.mytask.name, self.mytask, self.app.loader, "test", app=self.app)
            res = trace.trace_task_ret(self.mytask.name, uuid(), [4], {})
            self.assertEqual(res, 4 ** 4)
        finally:
            reset_worker_optimizations()
            self.assertIs(trace.trace_task_ret, trace._trace_task_ret)
        delattr(self.mytask, "__trace__")
        res = trace.trace_task_ret(self.mytask.name, uuid(), [4], {}, app=self.app)
        self.assertEqual(res, 4 ** 4)
Esempio n. 8
0
 def test_trace_task_ret__no_trace(self):
     try:
         delattr(self.mytask, '__trace__')
     except AttributeError:
         pass
     tid = uuid()
     message = self.TaskMessage(self.mytask.name, tid, args=[4])
     _, R, _ = trace_task_ret(
         self.mytask.name, tid, message.headers,
         message.body, message.content_type,
         message.content_encoding, app=self.app,
     )
     assert R == repr(4 ** 4)
Esempio n. 9
0
 def test_trace_task_ret(self):
     self.mytask.__trace__ = build_tracer(
         self.mytask.name, self.mytask, self.app.loader, 'test',
         app=self.app,
     )
     tid = uuid()
     message = self.TaskMessage(self.mytask.name, tid, args=[4])
     _, R, _ = trace_task_ret(
         self.mytask.name, tid, message.headers,
         message.body, message.content_type,
         message.content_encoding, app=self.app,
     )
     assert R == repr(4 ** 4)
Esempio n. 10
0
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()


def on_task(req):
    req.execute_using_pool(P)


def on_ack(*a):
    pass


m = Message(None, {}, {}, task)

x = Consumer(on_task, hostname=hostname, app=app)
x.update_strategies()
name = T.name
ts = time()
from celery.datastructures import AttributeDict
from celery.app.trace import trace_task_ret
request = AttributeDict(
    {
        'called_directly': False,
        'callbacks': [],
        'errbacks': [],
        'chord': None
    }, **task)
for i in range(100000):
    trace_task_ret(T, tid, (), {}, request)
print(time() - ts)
Esempio n. 11
0
tid = uuid()
P = TaskPool()
hostname = socket.gethostname()
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()

def on_task(req):
    req.execute_using_pool(P)

def on_ack(*a): pass


m = Message(None, {}, {}, task)

x = Consumer(on_task, hostname=hostname, app=app)
x.update_strategies()
name = T.name
ts = time()
from celery.datastructures import AttributeDict
from celery.app.trace import trace_task_ret
request = AttributeDict(
                {'called_directly': False,
                 'callbacks': [],
                 'errbacks': [],
                 'chord': None}, **task)
for i in range(100000):
    trace_task_ret(T, tid, (), {}, request)
print(time() - ts)