Skip to content

Commit b7f5598

Browse files
author
Emanuele Palazzetti
committed
[celery] test if patch() or unpatch() are called twice
1 parent e75bc70 commit b7f5598

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/contrib/celery/test_integration.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from nose.tools import eq_, ok_
44

5+
from ddtrace.contrib.celery import patch, unpatch
6+
57
from .base import CeleryBaseTestCase
68

79

@@ -21,6 +23,38 @@ def fn_task():
2123
traces = self.tracer.writer.pop_traces()
2224
eq_(100, len(traces))
2325

26+
def test_idempotent_patch(self):
27+
# calling patch() twice doesn't have side effects
28+
patch()
29+
30+
@self.app.task
31+
def fn_task():
32+
return 42
33+
34+
t = fn_task.apply()
35+
ok_(t.successful())
36+
eq_(42, t.result)
37+
38+
traces = self.tracer.writer.pop_traces()
39+
eq_(1, len(traces))
40+
eq_(1, len(traces[0]))
41+
42+
def test_idempotent_unpatch(self):
43+
# calling unpatch() twice doesn't have side effects
44+
unpatch()
45+
unpatch()
46+
47+
@self.app.task
48+
def fn_task():
49+
return 42
50+
51+
t = fn_task.apply()
52+
ok_(t.successful())
53+
eq_(42, t.result)
54+
55+
traces = self.tracer.writer.pop_traces()
56+
eq_(0, len(traces))
57+
2458
def test_fn_task_run(self):
2559
# the body of the function is not instrumented so calling it
2660
# directly doesn't create a trace

0 commit comments

Comments
 (0)