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

Commit 482c0f8

Browse files
committed
more cleanup
1 parent 69368fb commit 482c0f8

File tree

4 files changed

+66
-196
lines changed

4 files changed

+66
-196
lines changed

tests/mockserver_tests/test_basics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
unavailable_status,
3737
add_execute_streaming_sql_results,
3838
)
39-
from tests._helpers import is_multiplexed_enabled
4039

4140

4241
class TestBasics(MockServerTestBase):
@@ -105,11 +104,8 @@ def test_dbapi_partitioned_dml(self):
105104
requests[idx], BatchCreateSessionsRequest
106105
):
107106
idx += 1
108-
if (
109-
is_multiplexed_enabled(TransactionType.PARTITIONED)
110-
and idx < len(requests)
111-
and isinstance(requests[idx], CreateSessionRequest)
112-
):
107+
# Multiplexed sessions are always enabled - skip CreateSessionRequest
108+
if idx < len(requests) and isinstance(requests[idx], CreateSessionRequest):
113109
idx += 1
114110
begin_request: BeginTransactionRequest = requests[idx]
115111
self.assertEqual(

tests/system/test_dbapi.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
from google.cloud.spanner_v1 import gapic_version as package_version
3333
from google.api_core.datetime_helpers import DatetimeWithNanoseconds
3434

35-
from google.cloud.spanner_v1.database_sessions_manager import TransactionType
3635
from . import _helpers
37-
from tests._helpers import is_multiplexed_enabled
3836

3937
DATABASE_NAME = "dbapi-txn"
4038
SPANNER_RPC_PREFIX = "/google.spanner.v1.Spanner/"
@@ -161,20 +159,14 @@ def test_commit(self, client_side):
161159

162160
assert got_rows == [updated_row]
163161

164-
@pytest.mark.skipif(
165-
_helpers.USE_EMULATOR,
166-
reason="Emulator does not support multiple parallel transactions.",
162+
@pytest.mark.skip(
163+
reason="Multiplexed sessions can't be deleted and this test relies on session deletion."
167164
)
168165
def test_commit_exception(self):
169166
"""Test that if exception during commit method is caught, then
170167
subsequent operations on same Cursor and Connection object works
171168
properly."""
172169

173-
if is_multiplexed_enabled(transaction_type=TransactionType.READ_WRITE):
174-
pytest.skip(
175-
"Mutiplexed session can't be deleted and this test relies on session deletion."
176-
)
177-
178170
self._execute_common_statements(self._cursor)
179171
# deleting the session to fail the commit
180172
self._conn._session.delete()

tests/system/test_observability_options.py

Lines changed: 46 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
from mock import PropertyMock, patch
1717

1818
from google.cloud.spanner_v1.session import Session
19-
from google.cloud.spanner_v1.database_sessions_manager import TransactionType
2019
from . import _helpers
2120
from google.cloud.spanner_v1 import Client
2221
from google.api_core.exceptions import Aborted
2322
from google.auth.credentials import AnonymousCredentials
2423
from google.rpc import code_pb2
2524

26-
from .._helpers import is_multiplexed_enabled
2725

2826
HAS_OTEL_INSTALLED = False
2927

@@ -115,18 +113,9 @@ def test_propagation(enable_extended_tracing):
115113
) # "Expecting at least 2 spans from the injected trace exporter"
116114
gotNames = [span.name for span in from_inject_spans]
117115

118-
# Check if multiplexed sessions are enabled
119-
multiplexed_enabled = is_multiplexed_enabled(TransactionType.READ_ONLY)
120-
121-
# Determine expected session span name based on multiplexed sessions
122-
expected_session_span_name = (
123-
"CloudSpanner.CreateMultiplexedSession"
124-
if multiplexed_enabled
125-
else "CloudSpanner.CreateSession"
126-
)
127-
116+
# Multiplexed sessions are always enabled
128117
wantNames = [
129-
expected_session_span_name,
118+
"CloudSpanner.CreateMultiplexedSession",
130119
"CloudSpanner.Snapshot.execute_sql",
131120
]
132121
assert gotNames == wantNames
@@ -216,7 +205,6 @@ def test_transaction_abort_then_retry_spans(mock_session_id):
216205
from opentelemetry.trace.status import StatusCode
217206

218207
mock_session_id.return_value = session_id = "session-id"
219-
multiplexed = is_multiplexed_enabled(TransactionType.READ_WRITE)
220208

221209
db, trace_exporter = create_db_trace_exporter()
222210

@@ -238,60 +226,30 @@ def select_in_txn(txn):
238226

239227
got_statuses, got_events = finished_spans_statuses(trace_exporter)
240228

241-
# Check for the series of events
242-
if multiplexed:
243-
# With multiplexed sessions, there are no pool-related events
244-
want_events = [
245-
("Creating Session", {}),
246-
("Using session", {"id": session_id, "multiplexed": multiplexed}),
247-
("Returning session", {"id": session_id, "multiplexed": multiplexed}),
248-
(
249-
"Transaction was aborted in user operation, retrying",
250-
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
251-
),
252-
("Starting Commit", {}),
253-
("Commit Done", {}),
254-
]
255-
else:
256-
# With regular sessions, include pool-related events
257-
want_events = [
258-
("Acquiring session", {"kind": "BurstyPool"}),
259-
("Waiting for a session to become available", {"kind": "BurstyPool"}),
260-
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
261-
("Creating Session", {}),
262-
("Using session", {"id": session_id, "multiplexed": multiplexed}),
263-
("Returning session", {"id": session_id, "multiplexed": multiplexed}),
264-
(
265-
"Transaction was aborted in user operation, retrying",
266-
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
267-
),
268-
("Starting Commit", {}),
269-
("Commit Done", {}),
270-
]
229+
# Multiplexed sessions are always enabled, no pool-related events
230+
want_events = [
231+
("Creating Session", {}),
232+
("Using session", {"id": session_id, "multiplexed": True}),
233+
("Returning session", {"id": session_id, "multiplexed": True}),
234+
(
235+
"Transaction was aborted in user operation, retrying",
236+
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
237+
),
238+
("Starting Commit", {}),
239+
("Commit Done", {}),
240+
]
271241
assert got_events == want_events
272242

273-
# Check for the statues.
243+
# Check for the statuses
274244
codes = StatusCode
275-
if multiplexed:
276-
# With multiplexed sessions, the session span name is different
277-
want_statuses = [
278-
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
279-
("CloudSpanner.CreateMultiplexedSession", codes.OK, None),
280-
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
281-
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
282-
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
283-
("CloudSpanner.Transaction.commit", codes.OK, None),
284-
]
285-
else:
286-
# With regular sessions
287-
want_statuses = [
288-
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
289-
("CloudSpanner.CreateSession", codes.OK, None),
290-
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
291-
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
292-
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
293-
("CloudSpanner.Transaction.commit", codes.OK, None),
294-
]
245+
want_statuses = [
246+
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
247+
("CloudSpanner.CreateMultiplexedSession", codes.OK, None),
248+
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
249+
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
250+
("CloudSpanner.Transaction.execute_sql", codes.OK, None),
251+
("CloudSpanner.Transaction.commit", codes.OK, None),
252+
]
295253
assert got_statuses == want_statuses
296254

297255

@@ -417,19 +375,10 @@ def tx_update(txn):
417375
span_list = sorted(span_list, key=lambda span: span.start_time)
418376
got_span_names = [span.name for span in span_list]
419377

420-
# Check if multiplexed sessions are enabled for read-write transactions
421-
multiplexed_enabled = is_multiplexed_enabled(TransactionType.READ_WRITE)
422-
423-
# Determine expected session span name based on multiplexed sessions
424-
expected_session_span_name = (
425-
"CloudSpanner.CreateMultiplexedSession"
426-
if multiplexed_enabled
427-
else "CloudSpanner.CreateSession"
428-
)
429-
378+
# Multiplexed sessions are always enabled
430379
want_span_names = [
431380
"CloudSpanner.Database.run_in_transaction",
432-
expected_session_span_name,
381+
"CloudSpanner.CreateMultiplexedSession",
433382
"CloudSpanner.Session.run_in_transaction",
434383
"CloudSpanner.Transaction.commit",
435384
"CloudSpanner.Transaction.begin",
@@ -462,81 +411,38 @@ def test_database_partitioned_error():
462411
pass
463412

464413
got_statuses, got_events = finished_spans_statuses(trace_exporter)
465-
multiplexed_enabled = is_multiplexed_enabled(TransactionType.PARTITIONED)
466-
467-
if multiplexed_enabled:
468-
expected_event_names = [
469-
"Creating Session",
470-
"Using session",
471-
"Starting BeginTransaction",
472-
"Returning session",
473-
"exception",
474-
"exception",
475-
]
476-
assert len(got_events) == len(expected_event_names)
477-
for i, expected_name in enumerate(expected_event_names):
478-
assert got_events[i][0] == expected_name
479414

480-
assert got_events[1][1]["multiplexed"] is True
481-
482-
assert got_events[3][1]["multiplexed"] is True
483-
484-
for i in [4, 5]:
485-
assert (
486-
got_events[i][1]["exception.type"]
487-
== "google.api_core.exceptions.InvalidArgument"
488-
)
489-
assert (
490-
"Table not found: NonExistent" in got_events[i][1]["exception.message"]
491-
)
492-
else:
493-
expected_event_names = [
494-
"Acquiring session",
495-
"Waiting for a session to become available",
496-
"No sessions available in pool. Creating session",
497-
"Creating Session",
498-
"Using session",
499-
"Starting BeginTransaction",
500-
"Returning session",
501-
"exception",
502-
"exception",
503-
]
504-
505-
assert len(got_events) == len(expected_event_names)
506-
for i, expected_name in enumerate(expected_event_names):
507-
assert got_events[i][0] == expected_name
508-
509-
assert got_events[0][1]["kind"] == "BurstyPool"
510-
assert got_events[1][1]["kind"] == "BurstyPool"
511-
assert got_events[2][1]["kind"] == "BurstyPool"
512-
513-
assert got_events[4][1]["multiplexed"] is False
415+
# Multiplexed sessions are always enabled
416+
expected_event_names = [
417+
"Creating Session",
418+
"Using session",
419+
"Starting BeginTransaction",
420+
"Returning session",
421+
"exception",
422+
"exception",
423+
]
424+
assert len(got_events) == len(expected_event_names)
425+
for i, expected_name in enumerate(expected_event_names):
426+
assert got_events[i][0] == expected_name
514427

515-
assert got_events[6][1]["multiplexed"] is False
428+
assert got_events[1][1]["multiplexed"] is True
429+
assert got_events[3][1]["multiplexed"] is True
516430

517-
for i in [7, 8]:
518-
assert (
519-
got_events[i][1]["exception.type"]
520-
== "google.api_core.exceptions.InvalidArgument"
521-
)
522-
assert (
523-
"Table not found: NonExistent" in got_events[i][1]["exception.message"]
524-
)
431+
for i in [4, 5]:
432+
assert (
433+
got_events[i][1]["exception.type"]
434+
== "google.api_core.exceptions.InvalidArgument"
435+
)
436+
assert "Table not found: NonExistent" in got_events[i][1]["exception.message"]
525437

526438
codes = StatusCode
527-
528-
expected_session_span_name = (
529-
"CloudSpanner.CreateMultiplexedSession"
530-
if multiplexed_enabled
531-
else "CloudSpanner.CreateSession"
532-
)
533439
want_statuses = [
534440
(
535441
"CloudSpanner.Database.execute_partitioned_pdml",
536442
codes.ERROR,
537443
"InvalidArgument: 400 Table not found: NonExistent [at 1:8]\nUPDATE NonExistent SET name = 'foo' WHERE id > 1\n ^",
538444
),
539-
(expected_session_span_name, codes.OK, None),
445+
("CloudSpanner.CreateMultiplexedSession", codes.OK, None),
540446
(
541447
"CloudSpanner.ExecuteStreamingSql",
542448
codes.ERROR,

tests/system/test_session_api.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,8 @@ def handle_abort(self, database):
421421
self.handler_done.set()
422422

423423

424+
@pytest.mark.skip(reason="Multiplexed sessions do not support CRUD operations.")
424425
def test_session_crud(sessions_database):
425-
if is_multiplexed_enabled(transaction_type=TransactionType.READ_ONLY):
426-
pytest.skip("Multiplexed sessions do not support CRUD operations.")
427-
428426
session = sessions_database.session()
429427
assert not session.exists()
430428

@@ -457,33 +455,21 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
457455
nth_req0 = sampling_req_id[-2]
458456

459457
db = sessions_database
460-
multiplexed_enabled = is_multiplexed_enabled(TransactionType.READ_ONLY)
461458

462459
# [A] Verify batch checkout spans
463460
# -------------------------------
464461

465462
request_id_1 = f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 0}.1"
466463

467-
if multiplexed_enabled:
468-
assert_span_attributes(
469-
ot_exporter,
470-
"CloudSpanner.CreateMultiplexedSession",
471-
attributes=_make_attributes(
472-
db_name, x_goog_spanner_request_id=request_id_1
473-
),
474-
span=span_list[0],
475-
)
476-
else:
477-
assert_span_attributes(
478-
ot_exporter,
479-
"CloudSpanner.GetSession",
480-
attributes=_make_attributes(
481-
db_name,
482-
session_found=True,
483-
x_goog_spanner_request_id=request_id_1,
484-
),
485-
span=span_list[0],
486-
)
464+
# Multiplexed sessions are always enabled
465+
assert_span_attributes(
466+
ot_exporter,
467+
"CloudSpanner.CreateMultiplexedSession",
468+
attributes=_make_attributes(
469+
db_name, x_goog_spanner_request_id=request_id_1
470+
),
471+
span=span_list[0],
472+
)
487473

488474
assert_span_attributes(
489475
ot_exporter,
@@ -500,24 +486,14 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
500486
# ----------------------------------
501487

502488
if len(span_list) == 4:
503-
if multiplexed_enabled:
504-
expected_snapshot_span_name = "CloudSpanner.CreateMultiplexedSession"
505-
snapshot_session_attributes = _make_attributes(
506-
db_name,
507-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 2}.1",
508-
)
509-
else:
510-
expected_snapshot_span_name = "CloudSpanner.GetSession"
511-
snapshot_session_attributes = _make_attributes(
512-
db_name,
513-
session_found=True,
514-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 2}.1",
515-
)
516-
489+
# Multiplexed sessions are always enabled
517490
assert_span_attributes(
518491
ot_exporter,
519-
expected_snapshot_span_name,
520-
attributes=snapshot_session_attributes,
492+
"CloudSpanner.CreateMultiplexedSession",
493+
attributes=_make_attributes(
494+
db_name,
495+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 2}.1",
496+
),
521497
span=span_list[2],
522498
)
523499

0 commit comments

Comments
 (0)