Skip to content

Commit

Permalink
tests/unit/*tracing: pass current span into assertions
Browse files Browse the repository at this point in the history
This allows us to avoid the flakes with OpenTelemetry's
inMemorySpanExporter that might not have received the
exported spans yet.
  • Loading branch information
odeke-em committed Sep 20, 2024
1 parent f59084c commit ab23f09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ def assertSpanEvents(self, name, wantEventNames=[], span=None):
span = span_list[0]

self.assertEqual(span.name, name)
self.assertEqual(len(span.events), len(wantEventNames))
actualEventNames = []
for event in span.events:
actualEventNames.append(event.name)
self.assertEqual(actualEventNames, wantEventNames)
6 changes: 3 additions & 3 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_create_session_span_annotations(self):
database.spanner_api = gax_api
session = self._make_one(database, database_role=self.DATABASE_ROLE)

with trace_call("TestSessionSpan", session):
with trace_call("TestSessionSpan", session) as span:
session.create()

self.assertEqual(session.session_id, self.SESSION_ID)
Expand All @@ -209,8 +209,8 @@ def test_create_session_span_annotations(self):
],
)

wantEventNames = ["Acquiring session", "Creating Session", "Using Session"]
self.assertSpanEvents("CloudSpanner.CreateSession", wantEventNames)
wantEventNames = ["Creating Session", "Using Session"]
self.assertSpanEvents("TestSessionSpan", wantEventNames, span)

def test_create_wo_database_role(self):
from google.cloud.spanner_v1 import CreateSessionRequest
Expand Down

0 comments on commit ab23f09

Please sign in to comment.