Skip to content

Commit 98202f9

Browse files
author
Emanuele Palazzetti
committed
[tornado] add test for the context safe-guard
1 parent ade45b9 commit 98202f9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/contrib/tornado/test_safety.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TestAppSafety(TornadoTestCase):
4848
"""
4949
Ensure that the application patch has the proper safety guards.
5050
"""
51+
5152
def test_trace_unpatch(self):
5253
# the application must not be traced if unpatch() is called
5354
patch()
@@ -108,6 +109,27 @@ def test_arbitrary_resource_404(self):
108109
eq_('tornado.web.ErrorHandler', request_span.resource)
109110
eq_('/does_not_exist/', request_span.get_tag('http.url'))
110111

112+
@gen_test
113+
def test_futures_without_context(self):
114+
# ensures that if futures propagation is available, an empty
115+
# context doesn't crash the system
116+
from .web.compat import ThreadPoolExecutor
117+
118+
def job():
119+
with self.tracer.trace('job'):
120+
return 42
121+
122+
executor = ThreadPoolExecutor(max_workers=3)
123+
yield executor.submit(job)
124+
125+
traces = self.tracer.writer.pop_traces()
126+
eq_(1, len(traces))
127+
eq_(1, len(traces[0]))
128+
129+
# this trace yields the execution of the thread
130+
span = traces[0][0]
131+
eq_('job', span.name)
132+
111133

112134
class TestCustomAppSafety(TornadoTestCase):
113135
"""

0 commit comments

Comments
 (0)