Skip to content

Commit 7988ffa

Browse files
committed
Use guard to keep x-goog-request-id interceptor docile in tests until activation later
1 parent 7e24e61 commit 7988ffa

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

google/cloud/spanner_v1/testing/interceptors.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ def reset(self):
6868

6969

7070
X_GOOG_REQUEST_ID = "x-goog-spanner-request-id"
71-
# TODO:(@odeke-em): delete this guard when PR #1367 is merged.
72-
__X_GOOG_REQUEST_ID_FUNCTIONALITY_MERGED = False
7371

7472

7573
class XGoogRequestIDHeaderInterceptor(ClientInterceptor):
74+
# TODO:(@odeke-em): delete this guard when PR #1367 is merged.
75+
X_GOOG_REQUEST_ID_FUNCTIONALITY_MERGED = False
76+
7677
def __init__(self):
7778
self._unary_req_segments = []
7879
self._stream_req_segments = []
@@ -86,22 +87,24 @@ def intercept(self, method, request_or_iterator, call_details):
8687
x_goog_request_id = value
8788
break
8889

89-
if __X_GOOG_REQUEST_ID_FUNCTIONALITY_MERGED and not x_goog_request_id:
90+
if self.X_GOOG_REQUEST_ID_FUNCTIONALITY_MERGED and not x_goog_request_id:
9091
raise Exception(
9192
f"Missing {X_GOOG_REQUEST_ID} header in {call_details.method}"
9293
)
9394

9495
response_or_iterator = method(request_or_iterator, call_details)
9596
streaming = getattr(response_or_iterator, "__iter__", None) is not None
96-
with self.__lock:
97-
if streaming:
98-
self._stream_req_segments.append(
99-
(call_details.method, parse_request_id(x_goog_request_id))
100-
)
101-
else:
102-
self._unary_req_segments.append(
103-
(call_details.method, parse_request_id(x_goog_request_id))
104-
)
97+
98+
if self.X_GOOG_REQUEST_ID_FUNCTIONALITY_MERGED:
99+
with self.__lock:
100+
if streaming:
101+
self._stream_req_segments.append(
102+
(call_details.method, parse_request_id(x_goog_request_id))
103+
)
104+
else:
105+
self._unary_req_segments.append(
106+
(call_details.method, parse_request_id(x_goog_request_id))
107+
)
105108

106109
return response_or_iterator
107110

0 commit comments

Comments
 (0)