Skip to content

Commit 656432f

Browse files
committed
unittest
1 parent 22ea5e7 commit 656432f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/test_tracing.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@
4242

4343
event_samples = "tests/event_samples/"
4444

45+
span_to_finish = None
46+
47+
48+
def _clean_up_span():
49+
global span_to_finish
50+
if span_to_finish is not None:
51+
span_to_finish.finish()
52+
span_to_finish = None
53+
54+
55+
def register_span(span):
56+
global span_to_finish
57+
_clean_up_span()
58+
span_to_finish = span
59+
return span
60+
61+
62+
def wrapped_span_creator(span_creator_func):
63+
def result_func(*args, **kwargs):
64+
return register_span(span_creator_func(*args, **kwargs))
65+
66+
return result_func
67+
68+
69+
create_inferred_span = wrapped_span_creator(create_inferred_span)
70+
4571

4672
class ClientContext(object):
4773
def __init__(self, custom=None):
@@ -482,6 +508,7 @@ def test_set_correlation_ids(self):
482508
span = tracer.current_span()
483509
self.assertEqual(span.trace_id, 123)
484510
self.assertEqual(span.span_id, 456)
511+
span.finish()
485512

486513
def test_set_correlation_ids_handle_empty_trace_context(self):
487514
# neither x-ray or ddtrace is use. no tracing at all.
@@ -595,6 +622,9 @@ def setUp(self):
595622
self.mock_span_stop = patcher.start()
596623
self.addCleanup(patcher.stop)
597624

625+
def tearDown(self):
626+
_clean_up_span()
627+
598628
def test_create_inferred_span_from_authorizer_request_api_gateway_v1_event(self):
599629
event_sample_source = "authorizer-request-api-gateway-v1"
600630
finish_time = (
@@ -741,6 +771,9 @@ def _basic_common_checks(
741771

742772

743773
class TestInferredSpans(unittest.TestCase):
774+
def tearDown(self):
775+
_clean_up_span()
776+
744777
def test_create_inferred_span_from_api_gateway_event(self):
745778
event_sample_source = "api-gateway"
746779
test_file = event_samples + event_sample_source + ".json"

0 commit comments

Comments
 (0)