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

Commit 6dc6b4b

Browse files
committed
fix tests
1 parent 8899249 commit 6dc6b4b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

google/cloud/spanner_v1/database.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,15 +1578,20 @@ def _get_session(self):
15781578
all partitions have been processed.
15791579
"""
15801580
from google.cloud.spanner_v1.database import TransactionType
1581+
from google.cloud.spanner_v1.session import Session
15811582

1583+
15821584
if self._session is None:
1583-
session = self._session = self._database._session_manager.get_session(
1584-
TransactionType.READ_ONLY
1585-
)
1585+
database = self._database
1586+
15861587
if self._session_id is None:
1587-
session.create()
1588+
session = database._session_manager.get_session(TransactionType.READ_ONLY)
1589+
self._session_id = session.session_id
15881590
else:
1591+
session = Session(database=database)
15891592
session._session_id = self._session_id
1593+
1594+
self._session = session
15901595
return self._session
15911596

15921597
def _get_snapshot(self):

tests/system/test_observability_options.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
from google.auth.credentials import AnonymousCredentials
1717
from google.rpc import code_pb2
1818
import pytest
19+
from unittest.mock import patch, PropertyMock
1920

2021
from google.cloud.spanner_v1 import Client
22+
from google.cloud.spanner_v1.session import Session
2123

2224
from . import _helpers
2325

@@ -196,9 +198,15 @@ def create_db_trace_exporter():
196198
not HAS_OTEL_INSTALLED,
197199
reason="Tracing requires OpenTelemetry",
198200
)
199-
def test_transaction_abort_then_retry_spans():
201+
@patch.object(Session, "session_id", new_callable=PropertyMock)
202+
@patch.object(Session, "is_multiplexed", new_callable=PropertyMock)
203+
def test_transaction_abort_then_retry_spans(mock_session_multiplexed, mock_session_id):
200204
from opentelemetry.trace.status import StatusCode
201205

206+
# Mock session properties for testing.
207+
mock_session_multiplexed.return_value = session_multiplexed = False
208+
mock_session_id.return_value = session_id = "session-id"
209+
202210
db, trace_exporter = create_db_trace_exporter()
203211

204212
counters = dict(aborted=0)
@@ -225,12 +233,14 @@ def select_in_txn(txn):
225233
("Waiting for a session to become available", {"kind": "BurstyPool"}),
226234
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
227235
("Creating Session", {}),
236+
("Using session", {"id": session_id, "multiplexed": session_multiplexed}),
228237
(
229238
"Transaction was aborted in user operation, retrying",
230239
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
231240
),
232241
("Starting Commit", {}),
233242
("Commit Done", {}),
243+
("Returning session", {"id": session_id, "multiplexed": session_multiplexed}),
234244
]
235245
assert got_events == want_events
236246

@@ -392,9 +402,15 @@ def tx_update(txn):
392402
not HAS_OTEL_INSTALLED,
393403
reason="Tracing requires OpenTelemetry",
394404
)
395-
def test_database_partitioned_error():
405+
@patch.object(Session, "session_id", new_callable=PropertyMock)
406+
@patch.object(Session, "is_multiplexed", new_callable=PropertyMock)
407+
def test_database_partitioned_error(mock_session_multiplexed, mock_session_id):
396408
from opentelemetry.trace.status import StatusCode
397409

410+
# Mock session properties for testing.
411+
mock_session_multiplexed.return_value = session_multiplexed = False
412+
mock_session_id.return_value = session_id = "session-id"
413+
398414
db, trace_exporter = create_db_trace_exporter()
399415

400416
try:
@@ -409,6 +425,7 @@ def test_database_partitioned_error():
409425
("Waiting for a session to become available", {"kind": "BurstyPool"}),
410426
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
411427
("Creating Session", {}),
428+
("Using session", {"id": session_id, "multiplexed": session_multiplexed}),
412429
("Starting BeginTransaction", {}),
413430
(
414431
"exception",
@@ -428,6 +445,7 @@ def test_database_partitioned_error():
428445
"exception.escaped": "False",
429446
},
430447
),
448+
("Returning session", {"id": session_id, "multiplexed": session_multiplexed}),
431449
]
432450
assert got_events == want_events
433451

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.