|
24 | 24 | OpenTelemetryBase, |
25 | 25 | StatusCode, |
26 | 26 | enrich_with_otel_scope, |
| 27 | + HAS_OPENTELEMETRY_INSTALLED, |
27 | 28 | ) |
28 | 29 |
|
29 | 30 |
|
@@ -232,6 +233,9 @@ def test_get_non_expired(self): |
232 | 233 | self.assertFalse(pool._sessions.full()) |
233 | 234 |
|
234 | 235 | def test_spans_bind_get(self): |
| 236 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 237 | + return |
| 238 | + |
235 | 239 | # This tests retrieving 1 out of 4 sessions from the session pool. |
236 | 240 | pool = self._make_one(size=4) |
237 | 241 | database = _Database("name") |
@@ -271,6 +275,9 @@ def test_spans_bind_get(self): |
271 | 275 | self.assertSpanEvents("pool.Get", wantEventNames, span_list[-1]) |
272 | 276 |
|
273 | 277 | def test_spans_bind_get_empty_pool(self): |
| 278 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 279 | + return |
| 280 | + |
274 | 281 | # Tests trying to invoke pool.get() from an empty pool. |
275 | 282 | pool = self._make_one(size=0) |
276 | 283 | database = _Database("name") |
@@ -312,6 +319,9 @@ def test_spans_bind_get_empty_pool(self): |
312 | 319 | assert got_all_events == want_all_events |
313 | 320 |
|
314 | 321 | def test_spans_pool_bind(self): |
| 322 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 323 | + return |
| 324 | + |
315 | 325 | # Tests the exception generated from invoking pool.bind when |
316 | 326 | # you have an empty pool. |
317 | 327 | pool = self._make_one(size=1) |
@@ -524,6 +534,9 @@ def test_get_empty(self): |
524 | 534 | self.assertTrue(pool._sessions.empty()) |
525 | 535 |
|
526 | 536 | def test_spans_get_empty_pool(self): |
| 537 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 538 | + return |
| 539 | + |
527 | 540 | # This scenario tests a pool that hasn't been filled up |
528 | 541 | # and pool.get() acquires from a pool, waiting for a session |
529 | 542 | # to become available. |
@@ -877,6 +890,23 @@ def test_put_full(self): |
877 | 890 |
|
878 | 891 | self.assertTrue(pool._sessions.full()) |
879 | 892 |
|
| 893 | + def test_spans_put_full(self): |
| 894 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 895 | + return |
| 896 | + |
| 897 | + import queue |
| 898 | + |
| 899 | + pool = self._make_one(size=4) |
| 900 | + database = _Database("name") |
| 901 | + SESSIONS = [_Session(database)] * 4 |
| 902 | + database._sessions.extend(SESSIONS) |
| 903 | + pool.bind(database) |
| 904 | + |
| 905 | + with self.assertRaises(queue.Full): |
| 906 | + pool.put(_Session(database)) |
| 907 | + |
| 908 | + self.assertTrue(pool._sessions.full()) |
| 909 | + |
880 | 910 | span_list = self.get_finished_spans() |
881 | 911 | got_span_names = [span.name for span in span_list] |
882 | 912 | want_span_names = ["CloudSpanner.PingingPool.BatchCreateSessions"] |
@@ -991,6 +1021,9 @@ def test_ping_oldest_stale_and_not_exists(self): |
991 | 1021 | self.assertNoSpans() |
992 | 1022 |
|
993 | 1023 | def test_spans_get_and_leave_empty_pool(self): |
| 1024 | + if not HAS_OPENTELEMETRY_INSTALLED: |
| 1025 | + return |
| 1026 | + |
994 | 1027 | # This scenario tests the spans generated from pulling a span |
995 | 1028 | # out the pool and leaving it empty. |
996 | 1029 | pool = self._make_one() |
|
0 commit comments