fix tests · googleapis/python-spanner@841408a · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 841408a

Browse files
committed
fix tests
1 parent 15d245f commit 841408a

File tree

5 files changed

+94
-41
lines changed

5 files changed

+94
-41
lines changed

.github/workflows/integration-tests-against-emulator-with-multiplexed-session.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ jobs:
3131
GOOGLE_CLOUD_PROJECT: emulator-test-project
3232
GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE: true
3333
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: true
34+
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: true

tests/system/test_observability_options.py

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def tx_update(txn):
392392
reason="Tracing requires OpenTelemetry",
393393
)
394394
def test_database_partitioned_error():
395+
import os
395396
from opentelemetry.trace.status import StatusCode
396397

397398
db, trace_exporter = create_db_trace_exporter()
@@ -402,35 +403,86 @@ def test_database_partitioned_error():
402403
pass
403404

404405
got_statuses, got_events = finished_spans_statuses(trace_exporter)
405-
# Check for the series of events
406-
want_events = [
407-
("Acquiring session", {"kind": "BurstyPool"}),
408-
("Waiting for a session to become available", {"kind": "BurstyPool"}),
409-
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
410-
("Creating Session", {}),
411-
("Starting BeginTransaction", {}),
412-
(
406+
407+
# Check if multiplexed sessions are enabled for partitioned operations
408+
multiplexed_partitioned_enabled = (
409+
os.getenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS") == "true"
410+
)
411+
412+
# Define expected events based on whether multiplexed sessions are enabled
413+
if multiplexed_partitioned_enabled:
414+
# When multiplexed sessions are enabled for partitioned operations,
415+
# the execution path is different - sessions manager creates multiplexed sessions directly
416+
expected_event_names = [
417+
"Creating Session",
418+
"Using session",
419+
"Starting BeginTransaction",
420+
"Returning session",
413421
"exception",
414-
{
415-
"exception.type": "google.api_core.exceptions.InvalidArgument",
416-
"exception.message": "400 Table not found: NonExistent [at 1:8]\nUPDATE NonExistent SET name = 'foo' WHERE id > 1\n ^",
417-
"exception.stacktrace": "EPHEMERAL",
418-
"exception.escaped": "False",
419-
},
420-
),
421-
(
422422
"exception",
423-
{
424-
"exception.type": "google.api_core.exceptions.InvalidArgument",
425-
"exception.message": "400 Table not found: NonExistent [at 1:8]\nUPDATE NonExistent SET name = 'foo' WHERE id > 1\n ^",
426-
"exception.stacktrace": "EPHEMERAL",
427-
"exception.escaped": "False",
428-
},
429-
),
430-
]
431-
assert got_events == want_events
423+
]
424+
# Check that we have the expected events
425+
assert len(got_events) == len(expected_event_names)
426+
for i, expected_name in enumerate(expected_event_names):
427+
assert got_events[i][0] == expected_name
428+
429+
# Verify session usage event shows multiplexed session
430+
assert got_events[1][1]["multiplexed"] == True
431+
432+
# Verify session return event shows multiplexed session
433+
assert got_events[3][1]["multiplexed"] == True
434+
435+
# Verify the exception details
436+
for i in [4, 5]: # Both exception events
437+
assert (
438+
got_events[i][1]["exception.type"]
439+
== "google.api_core.exceptions.InvalidArgument"
440+
)
441+
assert (
442+
"Table not found: NonExistent" in got_events[i][1]["exception.message"]
443+
)
444+
else:
445+
# When multiplexed sessions are disabled, sessions manager still manages sessions
446+
# but uses regular pool sessions instead of multiplexed sessions
447+
expected_event_names = [
448+
"Acquiring session",
449+
"Waiting for a session to become available",
450+
"No sessions available in pool. Creating session",
451+
"Creating Session",
452+
"Using session",
453+
"Starting BeginTransaction",
454+
"Returning session",
455+
"exception",
456+
"exception",
457+
]
432458

433-
# Check for the statues.
459+
# Check that we have the expected events
460+
assert len(got_events) == len(expected_event_names)
461+
for i, expected_name in enumerate(expected_event_names):
462+
assert got_events[i][0] == expected_name
463+
464+
# Verify pool-related events
465+
assert got_events[0][1]["kind"] == "BurstyPool"
466+
assert got_events[1][1]["kind"] == "BurstyPool"
467+
assert got_events[2][1]["kind"] == "BurstyPool"
468+
469+
# Verify session usage event shows non-multiplexed session
470+
assert got_events[4][1]["multiplexed"] == False
471+
472+
# Verify session return event shows non-multiplexed session
473+
assert got_events[6][1]["multiplexed"] == False
474+
475+
# Verify the exception details
476+
for i in [7, 8]: # Both exception events
477+
assert (
478+
got_events[i][1]["exception.type"]
479+
== "google.api_core.exceptions.InvalidArgument"
480+
)
481+
assert (
482+
"Table not found: NonExistent" in got_events[i][1]["exception.message"]
483+
)
484+
485+
# Check for the statuses.
434486
codes = StatusCode
435487
want_statuses = [
436488
(

tests/system/test_session_api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
457457
attributes=_make_attributes(
458458
db_name,
459459
session_found=True,
460-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+0}.1",
460+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 0}.1",
461461
),
462462
span=span_list[0],
463463
)
@@ -467,7 +467,7 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
467467
attributes=_make_attributes(
468468
db_name,
469469
num_mutations=2,
470-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+1}.1",
470+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 1}.1",
471471
),
472472
span=span_list[1],
473473
)
@@ -477,7 +477,7 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
477477
attributes=_make_attributes(
478478
db_name,
479479
session_found=True,
480-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+2}.1",
480+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 2}.1",
481481
),
482482
span=span_list[2],
483483
)
@@ -488,7 +488,7 @@ def test_batch_insert_then_read(sessions_database, ot_exporter):
488488
db_name,
489489
columns=sd.COLUMNS,
490490
table_id=sd.TABLE,
491-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+3}.1",
491+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 3}.1",
492492
),
493493
span=span_list[3],
494494
)
@@ -664,7 +664,7 @@ def test_transaction_read_and_insert_then_rollback(
664664
attributes=dict(
665665
_make_attributes(
666666
db_name,
667-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+0}.1",
667+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 0}.1",
668668
),
669669
),
670670
span=span_list[0],
@@ -675,7 +675,7 @@ def test_transaction_read_and_insert_then_rollback(
675675
attributes=_make_attributes(
676676
db_name,
677677
session_found=True,
678-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+1}.1",
678+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 1}.1",
679679
),
680680
span=span_list[1],
681681
)
@@ -685,7 +685,7 @@ def test_transaction_read_and_insert_then_rollback(
685685
attributes=_make_attributes(
686686
db_name,
687687
num_mutations=1,
688-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+2}.1",
688+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 2}.1",
689689
),
690690
span=span_list[2],
691691
)
@@ -694,7 +694,7 @@ def test_transaction_read_and_insert_then_rollback(
694694
"CloudSpanner.Transaction.begin",
695695
attributes=_make_attributes(
696696
db_name,
697-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+3}.1",
697+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 3}.1",
698698
),
699699
span=span_list[3],
700700
)
@@ -705,7 +705,7 @@ def test_transaction_read_and_insert_then_rollback(
705705
db_name,
706706
table_id=sd.TABLE,
707707
columns=sd.COLUMNS,
708-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+4}.1",
708+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 4}.1",
709709
),
710710
span=span_list[4],
711711
)
@@ -716,7 +716,7 @@ def test_transaction_read_and_insert_then_rollback(
716716
db_name,
717717
table_id=sd.TABLE,
718718
columns=sd.COLUMNS,
719-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+5}.1",
719+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 5}.1",
720720
),
721721
span=span_list[5],
722722
)
@@ -725,7 +725,7 @@ def test_transaction_read_and_insert_then_rollback(
725725
"CloudSpanner.Transaction.rollback",
726726
attributes=_make_attributes(
727727
db_name,
728-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+6}.1",
728+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 6}.1",
729729
),
730730
span=span_list[6],
731731
)
@@ -736,7 +736,7 @@ def test_transaction_read_and_insert_then_rollback(
736736
db_name,
737737
table_id=sd.TABLE,
738738
columns=sd.COLUMNS,
739-
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0+7}.1",
739+
x_goog_spanner_request_id=f"1.{REQ_RAND_PROCESS_ID}.{db._nth_client_id}.{db._channel_id}.{nth_req0 + 7}.1",
740740
),
741741
span=span_list[7],
742742
)

tests/unit/test_pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_spans_bind_get(self):
261261
want_span_names = ["CloudSpanner.FixedPool.BatchCreateSessions", "pool.Get"]
262262
assert got_span_names == want_span_names
263263

264-
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id-1}.{database._channel_id}.{_Database.NTH_REQUEST.value}.1"
264+
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id - 1}.{database._channel_id}.{_Database.NTH_REQUEST.value}.1"
265265
attrs = dict(
266266
TestFixedSizePool.BASE_ATTRIBUTES.copy(), x_goog_spanner_request_id=req_id
267267
)
@@ -931,7 +931,7 @@ def test_spans_put_full(self):
931931
want_span_names = ["CloudSpanner.PingingPool.BatchCreateSessions"]
932932
assert got_span_names == want_span_names
933933

934-
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id-1}.{database._channel_id}.{_Database.NTH_REQUEST.value}.1"
934+
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id - 1}.{database._channel_id}.{_Database.NTH_REQUEST.value}.1"
935935
attrs = dict(
936936
TestPingingPool.BASE_ATTRIBUTES.copy(), x_goog_spanner_request_id=req_id
937937
)

tests/unit/test_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def test_iteration_w_multiple_span_creation(self):
608608
self.assertEqual(len(span_list), 2)
609609
for i, span in enumerate(span_list):
610610
self.assertEqual(span.name, name)
611-
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.{i+1}"
611+
req_id = f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.{i + 1}"
612612
self.assertEqual(
613613
dict(span.attributes),
614614
dict(

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.