diff --git a/tests/unit/test_pool.py b/tests/unit/test_pool.py index 6470b5329a..98824a25c5 100644 --- a/tests/unit/test_pool.py +++ b/tests/unit/test_pool.py @@ -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 = [] @@ -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) @@ -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 = { @@ -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):