Skip to content

Commit ab23f09

Browse files
committed
tests/unit/*tracing: pass current span into assertions
This allows us to avoid the flakes with OpenTelemetry's inMemorySpanExporter that might not have received the exported spans yet.
1 parent f59084c commit ab23f09

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

tests/_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ def assertSpanEvents(self, name, wantEventNames=[], span=None):
101101
span = span_list[0]
102102

103103
self.assertEqual(span.name, name)
104-
self.assertEqual(len(span.events), len(wantEventNames))
104+
actualEventNames = []
105+
for event in span.events:
106+
actualEventNames.append(event.name)
107+
self.assertEqual(actualEventNames, wantEventNames)

tests/unit/test_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_create_session_span_annotations(self):
189189
database.spanner_api = gax_api
190190
session = self._make_one(database, database_role=self.DATABASE_ROLE)
191191

192-
with trace_call("TestSessionSpan", session):
192+
with trace_call("TestSessionSpan", session) as span:
193193
session.create()
194194

195195
self.assertEqual(session.session_id, self.SESSION_ID)
@@ -209,8 +209,8 @@ def test_create_session_span_annotations(self):
209209
],
210210
)
211211

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

215215
def test_create_wo_database_role(self):
216216
from google.cloud.spanner_v1 import CreateSessionRequest

0 commit comments

Comments
 (0)