| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import pytest |
| 22 |
from opentracing import Format, SpanContextCorruptedException, \ |
| 23 |
UnsupportedFormatException |
| 24 |
from opentracing.mocktracer import MockTracer |
| 25 |
|
| 26 |
|
| 27 |
def test_propagation(): |
| 28 |
tracer = MockTracer() |
| 29 |
sp = tracer.start_span(operation_name='test') |
| 30 |
sp.set_baggage_item('foo', 'bar') |
| 31 |
|
| 32 |
|
| 33 |
with pytest.raises(UnsupportedFormatException): |
| 34 |
tracer.inject(sp.context, 'invalid', {}) |
| 35 |
with pytest.raises(UnsupportedFormatException): |
| 36 |
tracer.extract('invalid', {}) |
| 37 |
|
| 38 |
tests = [(Format.BINARY, bytearray()), |
| 39 |
(Format.TEXT_MAP, {})] |
| 40 |
for format, carrier in tests: |
| 41 |
tracer.inject(sp.context, format, carrier) |
| 42 |
extracted_ctx = tracer.extract(format, carrier) |
| 43 |
|
| 44 |
assert extracted_ctx.trace_id == sp.context.trace_id |
| 45 |
assert extracted_ctx.span_id == sp.context.span_id |
| 46 |
assert extracted_ctx.baggage == sp.context.baggage |
| 47 |
|
| 48 |
|
| 49 |
def test_propagation_extract_corrupted_data(): |
| 50 |
tracer = MockTracer() |
| 51 |
|
| 52 |
tests = [(Format.BINARY, bytearray()), |
| 53 |
(Format.TEXT_MAP, {})] |
| 54 |
for format, carrier in tests: |
| 55 |
with pytest.raises(SpanContextCorruptedException): |
| 56 |
tracer.extract(format, carrier) |
| 57 |
|
| 58 |
|
| 59 |
def test_start_span(): |
| 60 |
""" Test in process child span creation.""" |
| 61 |
tracer = MockTracer() |
| 62 |
sp = tracer.start_span(operation_name='test') |
| 63 |
sp.set_baggage_item('foo', 'bar') |
| 64 |
|
| 65 |
child = tracer.start_span( |
| 66 |
operation_name='child', child_of=sp.context) |
| 67 |
assert child.context.trace_id == sp.context.trace_id |
| 68 |
assert child.context.baggage == sp.context.baggage |
| 69 |
assert child.parent_id == sp.context.span_id |