Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 56f97a2

Browse files
committed
Address code review requests
1 parent 6fba449 commit 56f97a2

File tree

3 files changed

+21
-51
lines changed

3 files changed

+21
-51
lines changed

tests/system/test_observability_options.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def test_transaction_update_implicit_begin_nested_inside_commit():
302302
LABELS = {"test": "true"}
303303

304304
def tx_update(txn):
305-
txn.update(
305+
txn.insert(
306306
"Singers",
307307
columns=["SingerId", "FirstName"],
308308
values=[["1", "Bryan"], ["2", "Slash"]],
@@ -439,18 +439,13 @@ def test_database_partitioned_error():
439439
codes.ERROR,
440440
"InvalidArgument: 400 Table not found: NonExistent [at 1:8]\nUPDATE NonExistent SET name = 'foo' WHERE id > 1\n ^",
441441
),
442-
(
443-
"CloudSpanner.CreateSession",
444-
codes.OK,
445-
None,
446-
),
442+
("CloudSpanner.CreateSession", codes.OK, None),
447443
(
448444
"CloudSpanner.ExecuteStreamingSql",
449445
codes.ERROR,
450446
"InvalidArgument: 400 Table not found: NonExistent [at 1:8]\nUPDATE NonExistent SET name = 'foo' WHERE id > 1\n ^",
451447
),
452448
]
453-
print("got_statuses", got_statuses)
454449
assert got_statuses == want_statuses
455450

456451

tests/unit/test_database.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515

16+
import unittest
17+
1618
import mock
1719
from google.api_core import gapic_v1
1820
from google.cloud.spanner_admin_database_v1 import (
@@ -22,10 +24,6 @@
2224
from google.cloud.spanner_v1.param_types import INT64
2325
from google.api_core.retry import Retry
2426
from google.protobuf.field_mask_pb2 import FieldMask
25-
from tests._helpers import (
26-
HAS_OPENTELEMETRY_INSTALLED,
27-
OpenTelemetryBase,
28-
)
2927

3028
from google.cloud.spanner_v1 import RequestOptions, DirectedReadOptions
3129

@@ -64,7 +62,7 @@ class _CredentialsWithScopes(
6462
return mock.Mock(spec=_CredentialsWithScopes)
6563

6664

67-
class _BaseTest(OpenTelemetryBase):
65+
class _BaseTest(unittest.TestCase):
6866
PROJECT_ID = "project-id"
6967
PARENT = "projects/" + PROJECT_ID
7068
INSTANCE_ID = "instance-id"
@@ -1435,18 +1433,6 @@ def test_run_in_transaction_w_args(self):
14351433
self.assertEqual(committed, NOW)
14361434
self.assertEqual(session._retried, (_unit_of_work, (SINCE,), {"until": UNTIL}))
14371435

1438-
if not HAS_OPENTELEMETRY_INSTALLED:
1439-
pass
1440-
1441-
span_list = self.get_finished_spans()
1442-
got_span_names = [span.name for span in span_list]
1443-
want_span_names = ["CloudSpanner.Database.run_in_transaction"]
1444-
assert got_span_names == want_span_names
1445-
1446-
got_span_events_statuses = self.finished_spans_events_statuses()
1447-
want_span_events_statuses = []
1448-
assert got_span_events_statuses == want_span_events_statuses
1449-
14501436
def test_run_in_transaction_nested(self):
14511437
from datetime import datetime
14521438

tests/unit/test_transaction.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def test_rollback_not_begun(self):
229229

230230
# Since there was no transaction to be rolled back, rollback rpc is not called.
231231
api.rollback.assert_not_called()
232+
232233
self.assertNoSpans()
233234

234235
def test_rollback_already_committed(self):
@@ -298,17 +299,10 @@ def test_rollback_ok(self):
298299
],
299300
)
300301

301-
if not HAS_OPENTELEMETRY_INSTALLED:
302-
pass
303-
304-
span_list = self.get_finished_spans()
305-
got_span_names = [span.name for span in span_list]
306-
want_span_names = ["CloudSpanner.Transaction.rollback"]
307-
assert got_span_names == want_span_names
308-
309-
got_span_events_statuses = self.finished_spans_events_statuses()
310-
want_span_events_statuses = []
311-
assert got_span_events_statuses == want_span_events_statuses
302+
self.assertSpanAttributes(
303+
"CloudSpanner.Transaction.rollback",
304+
attributes=TestTransaction.BASE_ATTRIBUTES,
305+
)
312306

313307
def test_commit_not_begun(self):
314308
session = _Session()
@@ -317,7 +311,7 @@ def test_commit_not_begun(self):
317311
transaction.commit()
318312

319313
if not HAS_OPENTELEMETRY_INSTALLED:
320-
pass
314+
return
321315

322316
span_list = self.get_finished_spans()
323317
got_span_names = [span.name for span in span_list]
@@ -347,7 +341,7 @@ def test_commit_already_committed(self):
347341
transaction.commit()
348342

349343
if not HAS_OPENTELEMETRY_INSTALLED:
350-
pass
344+
return
351345

352346
span_list = self.get_finished_spans()
353347
got_span_names = [span.name for span in span_list]
@@ -377,7 +371,7 @@ def test_commit_already_rolled_back(self):
377371
transaction.commit()
378372

379373
if not HAS_OPENTELEMETRY_INSTALLED:
380-
pass
374+
return
381375

382376
span_list = self.get_finished_spans()
383377
got_span_names = [span.name for span in span_list]
@@ -503,7 +497,7 @@ def _commit_helper(
503497
)
504498

505499
if not HAS_OPENTELEMETRY_INSTALLED:
506-
pass
500+
return
507501

508502
span_list = self.get_finished_spans()
509503
got_span_names = [span.name for span in span_list]
@@ -665,18 +659,13 @@ def _execute_update_helper(
665659
)
666660

667661
self.assertEqual(transaction._execute_sql_count, count + 1)
668-
669-
if not HAS_OPENTELEMETRY_INSTALLED:
670-
pass
671-
672-
span_list = self.get_finished_spans()
673-
got_span_names = [span.name for span in span_list]
674-
want_span_names = ["CloudSpanner.Transaction.execute_update"]
675-
assert got_span_names == want_span_names
676-
677-
got_span_events_statuses = self.finished_spans_events_statuses()
678-
want_span_events_statuses = []
679-
assert got_span_events_statuses == want_span_events_statuses
662+
want_span_attributes = dict(TestTransaction.BASE_ATTRIBUTES)
663+
want_span_attributes["db.statement"] = DML_QUERY_WITH_PARAM
664+
self.assertSpanAttributes(
665+
"CloudSpanner.Transaction.execute_update",
666+
status=StatusCode.OK,
667+
attributes=want_span_attributes,
668+
)
680669

681670
def test_execute_update_new_transaction(self):
682671
self._execute_update_helper()

0 commit comments

Comments
 (0)