Debian Codegraph @

testbed/test_subtask_span_propagation/test_contextvars.py

raw symbols SCIP
1 from __future__ import absolute_import, print_function
2
3 import asyncio
4
5 from opentracing.mocktracer import MockTracer
6 from opentracing.scope_managers.asyncio import AsyncioScopeManager
7 from ..testcase import OpenTracingTestCase
8
9
10 class TestAsyncioContextVars(OpenTracingTestCase):
11 def setUp(self):
12 self.tracer = MockTracer(AsyncioScopeManager())
13 self.loop = asyncio.get_event_loop()
14
15 def test_main(self):
16 res = self.loop.run_until_complete(self.parent_task('message'))
17 self.assertEqual(res, 'message::response')
18
19 child, parent = self.tracer.finished_spans()
20 self.assertEmptySpan(child, 'child')
21 self.assertEmptySpan(parent, 'parent')
22 self.assertIsChildOf(child, parent)
23
24 async def parent_task(self, message):
25 with self.tracer.start_active_span('parent'):
26 res = await self.child_task(message)
27
28 return res
29
30 async def child_task(self, message):
31 with self.tracer.start_active_span('child'):
32 return '%s::response' % message