Skip to content

Commit 8c27fc6

Browse files
committed
Address code review requests
1 parent 6fba449 commit 8c27fc6

File tree

3 files changed

+16
-47
lines changed

3 files changed

+16
-47
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: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import unittest
1516

1617
import mock
1718
from google.api_core import gapic_v1
@@ -22,10 +23,6 @@
2223
from google.cloud.spanner_v1.param_types import INT64
2324
from google.api_core.retry import Retry
2425
from google.protobuf.field_mask_pb2 import FieldMask
25-
from tests._helpers import (
26-
HAS_OPENTELEMETRY_INSTALLED,
27-
OpenTelemetryBase,
28-
)
2926

3027
from google.cloud.spanner_v1 import RequestOptions, DirectedReadOptions
3128

@@ -64,7 +61,7 @@ class _CredentialsWithScopes(
6461
return mock.Mock(spec=_CredentialsWithScopes)
6562

6663

67-
class _BaseTest(OpenTelemetryBase):
64+
class _BaseTest(unittest.TestCase):
6865
PROJECT_ID = "project-id"
6966
PARENT = "projects/" + PROJECT_ID
7067
INSTANCE_ID = "instance-id"
@@ -1435,18 +1432,6 @@ def test_run_in_transaction_w_args(self):
14351432
self.assertEqual(committed, NOW)
14361433
self.assertEqual(session._retried, (_unit_of_work, (SINCE,), {"until": UNTIL}))
14371434

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-
14501435
def test_run_in_transaction_nested(self):
14511436
from datetime import datetime
14521437

tests/unit/test_transaction.py

Lines changed: 12 additions & 23 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()
@@ -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)