Skip to content

Commit 44b2862

Browse files
committed
Address code review requests
1 parent c953e5b commit 44b2862

File tree

3 files changed

+20
-87
lines changed

3 files changed

+20
-87
lines changed

tests/system/test_observability_options.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def test_transaction_update_implicit_begin_nested_inside_commit():
298298
LABELS = {"test": "true"}
299299

300300
def tx_update(txn):
301-
txn.update(
301+
txn.insert(
302302
"Singers",
303303
columns=["SingerId", "FirstName"],
304304
values=[["1", "Bryan"], ["2", "Slash"]],
@@ -403,60 +403,19 @@ def tx_update(txn):
403403
("Waiting for a session to become available", {"kind": "BurstyPool"}),
404404
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
405405
("Creating Session", {}),
406-
(
407-
"exception",
408-
{
409-
"exception.type": "google.api_core.exceptions.NotFound",
410-
"exception.message": "404 Table Singers: Row {Int64(1)} not found.",
411-
"exception.stacktrace": "EPHEMERAL",
412-
"exception.escaped": "False",
413-
},
414-
),
415-
(
416-
"Transaction.commit failed due to GoogleAPICallError, not retrying",
417-
{"attempt": 1},
418-
),
419-
(
420-
"exception",
421-
{
422-
"exception.type": "google.api_core.exceptions.NotFound",
423-
"exception.message": "404 Table Singers: Row {Int64(1)} not found.",
424-
"exception.stacktrace": "EPHEMERAL",
425-
"exception.escaped": "False",
426-
},
427-
),
428406
("Starting Commit", {}),
429-
(
430-
"exception",
431-
{
432-
"exception.type": "google.api_core.exceptions.NotFound",
433-
"exception.message": "404 Table Singers: Row {Int64(1)} not found.",
434-
"exception.stacktrace": "EPHEMERAL",
435-
"exception.escaped": "False",
436-
},
437-
),
407+
("Commit Done", {}),
438408
]
409+
print("got_events", got_events)
439410
assert got_events == want_events
440411

441412
# Check for the statues.
442413
codes = StatusCode
443414
want_statuses = [
444-
(
445-
"CloudSpanner.Database.run_in_transaction",
446-
codes.ERROR,
447-
"NotFound: 404 Table Singers: Row {Int64(1)} not found.",
448-
),
415+
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
449416
("CloudSpanner.CreateSession", codes.OK, None),
450-
(
451-
"CloudSpanner.Session.run_in_transaction",
452-
codes.ERROR,
453-
"NotFound: 404 Table Singers: Row {Int64(1)} not found.",
454-
),
455-
(
456-
"CloudSpanner.Transaction.commit",
457-
codes.ERROR,
458-
"NotFound: 404 Table Singers: Row {Int64(1)} not found.",
459-
),
417+
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
418+
("CloudSpanner.Transaction.commit", codes.OK, None),
460419
("CloudSpanner.Transaction.begin", codes.OK, None),
461420
]
462421
assert got_statuses == want_statuses

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)