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

Commit 9ce98c3

Browse files
committed
Take into account current behavior of /GetSession /BatchCreateSession in tests
1 parent d4bf747 commit 9ce98c3

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

google/cloud/spanner_v1/testing/database_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def spanner_api(self):
7979
channel = grpc.insecure_channel(self._instance.emulator_host)
8080
self._x_goog_request_id_interceptor = XGoogRequestIDHeaderInterceptor()
8181
self._interceptors.append(self._x_goog_request_id_interceptor)
82-
# print("self._interceptors", self._interceptors)
8382
channel = grpc.intercept_channel(channel, *self._interceptors)
8483
transport = SpannerGrpcTransport(channel=channel)
8584
self._spanner_api = SpannerClient(

google/cloud/spanner_v1/testing/interceptors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ def intercept(self, method, request_or_iterator, call_details):
9090
)
9191

9292
response_or_iterator = method(request_or_iterator, call_details)
93-
print("call_details", call_details, "\n", response_or_iterator)
9493
streaming = getattr(response_or_iterator, "__iter__", None) is not None
95-
print("x_append", call_details.method, x_goog_request_id)
9694
with self.__lock:
9795
if streaming:
9896
self._stream_req_segments.append(

tests/mockserver_tests/test_request_id_header.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ def test_snapshot_execute_sql(self):
7373
assert got_stream_segments == want_stream_segments
7474

7575
def test_snapshot_read_concurrent(self):
76+
db = self.database
7677
# Trigger BatchCreateSessions firstly.
77-
with self.database.snapshot() as snapshot:
78+
with db.snapshot() as snapshot:
7879
rows = snapshot.execute_sql("select 1")
7980
for row in rows:
8081
_ = row
8182

8283
# The other requests can then proceed.
8384
def select1():
84-
with self.database.snapshot() as snapshot:
85+
with db.snapshot() as snapshot:
8586
rows = snapshot.execute_sql("select 1")
8687
res_list = []
8788
for row in rows:
@@ -112,17 +113,56 @@ def select1():
112113
requests = self.spanner_service.requests
113114
self.assertEqual(2 + n * 2, len(requests), msg=requests)
114115

115-
client_id = self.database._nth_client_id
116-
channel_id = self.database._channel_id
116+
client_id = db._nth_client_id
117+
channel_id = db._channel_id
117118
got_stream_segments, got_unary_segments = self.canonicalize_request_id_headers()
118119

119120
want_unary_segments = [
120121
(
121122
"/google.spanner.v1.Spanner/BatchCreateSessions",
122123
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 1, 1),
123124
),
125+
(
126+
"/google.spanner.v1.Spanner/GetSession",
127+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 3, 1),
128+
),
129+
(
130+
"/google.spanner.v1.Spanner/GetSession",
131+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 5, 1),
132+
),
133+
(
134+
"/google.spanner.v1.Spanner/GetSession",
135+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 7, 1),
136+
),
137+
(
138+
"/google.spanner.v1.Spanner/GetSession",
139+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 9, 1),
140+
),
141+
(
142+
"/google.spanner.v1.Spanner/GetSession",
143+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 11, 1),
144+
),
145+
(
146+
"/google.spanner.v1.Spanner/GetSession",
147+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 13, 1),
148+
),
149+
(
150+
"/google.spanner.v1.Spanner/GetSession",
151+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 15, 1),
152+
),
153+
(
154+
"/google.spanner.v1.Spanner/GetSession",
155+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 17, 1),
156+
),
157+
(
158+
"/google.spanner.v1.Spanner/GetSession",
159+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 19, 1),
160+
),
161+
(
162+
"/google.spanner.v1.Spanner/GetSession",
163+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 21, 1),
164+
),
124165
]
125-
print("got_unary", got_unary_segments)
126166
assert got_unary_segments == want_unary_segments
127167

128168
want_stream_segments = [
@@ -132,39 +172,43 @@ def select1():
132172
),
133173
(
134174
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
135-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 3, 1),
175+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 4, 1),
136176
),
137177
(
138178
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
139-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 4, 1),
179+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 6, 1),
140180
),
141181
(
142182
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
143-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 5, 1),
183+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 8, 1),
144184
),
145185
(
146186
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
147-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 6, 1),
187+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 10, 1),
148188
),
149189
(
150190
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
151-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 7, 1),
191+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 12, 1),
152192
),
153193
(
154194
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
155-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 8, 1),
195+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 14, 1),
156196
),
157197
(
158198
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
159-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 9, 1),
199+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 16, 1),
160200
),
161201
(
162202
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
163-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 10, 1),
203+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 18, 1),
164204
),
165205
(
166206
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
167-
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 11, 1),
207+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 20, 1),
208+
),
209+
(
210+
"/google.spanner.v1.Spanner/ExecuteStreamingSql",
211+
(1, REQ_RAND_PROCESS_ID, client_id, channel_id, 22, 1),
168212
),
169213
]
170214
assert got_stream_segments == want_stream_segments
@@ -265,7 +309,6 @@ def test_unary_retryable_error(self):
265309
)
266310
]
267311

268-
print("got_unary_segments", got_unary_segments)
269312
assert got_unary_segments == want_unary_segments
270313
assert got_stream_segments == want_stream_segments
271314

0 commit comments

Comments
 (0)