Skip to content

Commit

Permalink
Fix tests to conform
Browse files Browse the repository at this point in the history
  • Loading branch information
praxist committed Jul 22, 2021
1 parent fc66d51 commit 069b6af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions tests/integration/pyramid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ def _register_mock(context, server_span):

@mock.patch("random.getrandbits")
def test_no_trace_headers(self, getrandbits):
getrandbits.return_value = 1234
getrandbits.return_value = 3735928559
self.test_app.get("/example")

self.assertEqual(self.observer.on_server_span_created.call_count, 1)

context, server_span = self.observer.on_server_span_created.call_args[0]
self.assertEqual(server_span.trace_id, "1234")
self.assertEqual(server_span.trace_id, "0" * 24 + "deadbeef")
self.assertEqual(server_span.parent_id, None)
self.assertEqual(server_span.id, "1234")
self.assertEqual(server_span.id, "0" * 8 + "deadbeef")

self.assertTrue(self.server_observer.on_start.called)
self.assertTrue(self.server_observer.on_finish.called)
Expand Down Expand Up @@ -222,17 +222,17 @@ def test_exception_in_exception_view_caught(self):

@mock.patch("random.getrandbits")
def test_distrust_headers(self, getrandbits):
getrandbits.return_value = 9999
getrandbits.return_value = 3735928559
self.baseplate_configurator.header_trust_handler.trust_headers = False

self.test_app.get(
"/example", headers={"X-Trace": "1234", "X-Parent": "2345", "X-Span": "3456"}
)

context, server_span = self.observer.on_server_span_created.call_args[0]
self.assertEqual(server_span.trace_id, str(getrandbits.return_value))
self.assertEqual(server_span.trace_id, "0" * 24 + "deadbeef")
self.assertEqual(server_span.parent_id, None)
self.assertEqual(server_span.id, str(getrandbits.return_value))
self.assertEqual(server_span.id, "0" * 8 + "deadbeef")

def test_local_trace_in_context(self):
self.test_app.get("/trace_context")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tracing_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_trace_on_inbound_request(self):
span = self.server_span_observer._serialize()
self.assertEqual(span["name"], "example")
self.assertEqual(len(span["annotations"]), 2)
self.assertEqual(span["parentId"], 0)
self.assertFalse("parentId" in span)

def test_local_tracing_embedded(self):
with mock.patch.object(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/observers/tracing_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ def test_to_span_obj_sets_parent_id(self):
span_obj = self.test_span_observer._to_span_obj([], [])
self.assertEqual(span_obj["parentId"], self.span.parent_id)

def test_to_span_obj_sets_default_parent_id(self):
def test_to_span_obj_default_no_parent_id(self):
self.span.parent_id = None
span_obj = self.test_span_observer._to_span_obj([], [])
self.assertEqual(span_obj["parentId"], 0)
self.assertFalse("parentId" in span_obj)

def test_incr_tag_adds_binary_annotation(self):
self.test_span_observer.binary_annotations = []
Expand Down

0 comments on commit 069b6af

Please sign in to comment.