1616from mock import PropertyMock , patch
1717
1818from google .cloud .spanner_v1 .session import Session
19- from google .cloud .spanner_v1 .database_sessions_manager import TransactionType
2019from . import _helpers
2120from google .cloud .spanner_v1 import Client
2221from google .api_core .exceptions import Aborted
2322from google .auth .credentials import AnonymousCredentials
2423from google .rpc import code_pb2
2524
26- from .._helpers import is_multiplexed_enabled
2725
2826HAS_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]\n UPDATE 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 ,
0 commit comments