Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Nov 14, 2024
1 parent ddc87dd commit ec2a959
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions tests/unit/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_spans_bind_get(self):
]
self.assertSpanEvents("CloudSpanner.BatchCreateSessions", wantEventNames)

def test_spans_get_on_empty(self):
def test_spans_get_create_sessions(self):
pool = self._make_one(size=1)
database = _Database("name")
SESSIONS = []
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_get_empty(self):
session.create.assert_called()
self.assertTrue(pool._sessions.empty())

def test_spans_get_empty(self):
def test_spans_get_empty_pool(self):
pool = self._make_one()
database = _Database("name")
session1 = _Session(database)
Expand Down Expand Up @@ -832,6 +832,33 @@ def test_ping_oldest_stale_and_not_exists(self):
SESSIONS[1].create.assert_called()
self.assertNoSpans()

def test_spans_get_empty_pool(self):
pool = self._make_one()
database = _Database("name")
session1 = _Session(database)
database._sessions.append(session1)
try:
pool.bind(database)
except:
pass

with trace_call("pool.Get", session1) as span:
session = pool.get()
self.assertIsInstance(session, _Session)
self.assertIs(session._database, database)
# session.create.assert_called()
self.assertTrue(pool._sessions.empty())

self.assertSpanAttributes(
"pool.Get",
attributes=TestPingingPool.BASE_ATTRIBUTES,
)
wantEventNames = [
"Waiting for a session to become available",
"Acquired session",
]
self.assertSpanEvents("pool.Get", wantEventNames)


class TestTransactionPingingPool(OpenTelemetryBase):
BASE_ATTRIBUTES = {
Expand Down Expand Up @@ -1035,6 +1062,34 @@ def test_begin_pending_transactions_non_empty(self):
self.assertTrue(pending.empty())
self.assertNoSpans()

def test_spans_get_empty_pool(self):
pool = self._make_one()
database = _Database("name")
session1 = _Session(database)
database._sessions.append(session1)
try:
pool.bind(database)
except:
pass

with trace_call("pool.Get", session1) as span:
try:
session = pool.get()
except:
pass

self.assertTrue(pool._sessions.empty())

self.assertSpanAttributes(
"pool.Get",
attributes=TestTransactionPingingPool.BASE_ATTRIBUTES,
)
wantEventNames = [
"Waiting for a session to become available",
"No session available",
]
self.assertSpanEvents("pool.Get", wantEventNames)


class TestSessionCheckout(unittest.TestCase):
def _getTargetClass(self):
Expand Down

0 comments on commit ec2a959

Please sign in to comment.