File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 22
33from nose .tools import eq_ , ok_
44
5+ from ddtrace .contrib .celery import patch , unpatch
6+
57from .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
You can’t perform that action at this time.
0 commit comments