Skip to content

Commit 086dd46

Browse files
fix: Test failures due to grpcio changes (#1178)
1 parent ff229a5 commit 086dd46

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,28 @@ def test_init_w_api_endpoint(creds):
133133
client_options = {"api_endpoint": "testendpoint.google.com"}
134134
client = publisher.Client(client_options=client_options, credentials=creds)
135135

136+
# Behavior to include dns prefix changed in gRPCv1.63
137+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
138+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
139+
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
140+
else:
141+
_EXPECTED_TARGET = "testendpoint.google.com:443"
136142
assert (client._transport.grpc_channel._channel.target()).decode(
137143
"utf-8"
138-
) == "testendpoint.google.com:443"
144+
) == _EXPECTED_TARGET
139145

140146

141147
def test_init_w_empty_client_options(creds):
142148
client = publisher.Client(client_options={}, credentials=creds)
143-
149+
# Behavior to include dns prefix changed in gRPCv1.63
150+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
151+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
152+
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
153+
else:
154+
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
144155
assert (client._transport.grpc_channel._channel.target()).decode(
145156
"utf-8"
146-
) == publisher_client.PublisherClient.SERVICE_ADDRESS
157+
) == _EXPECTED_TARGET
147158

148159

149160
def test_init_client_options_pass_through():
@@ -182,7 +193,13 @@ def test_init_emulator(monkeypatch):
182193
# Sadly, there seems to be no good way to do this without poking at
183194
# the private API of gRPC.
184195
channel = client._transport.publish._channel
185-
assert channel.target().decode("utf8") == "/foo/bar:123"
196+
# Behavior to include dns prefix changed in gRPCv1.63
197+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
198+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
199+
_EXPECTED_TARGET = "dns:////foo/bar:123"
200+
else:
201+
_EXPECTED_TARGET = "/foo/bar:123"
202+
assert channel.target().decode("utf8") == _EXPECTED_TARGET
186203

187204

188205
def test_message_ordering_enabled(creds):

tests/unit/pubsub_v1/subscriber/test_subscriber_client.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,28 @@ def test_init_w_api_endpoint(creds):
6666
client_options = {"api_endpoint": "testendpoint.google.com"}
6767
client = subscriber.Client(client_options=client_options, credentials=creds)
6868

69+
# Behavior to include dns prefix changed in gRPCv1.63
70+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
71+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
72+
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
73+
else:
74+
_EXPECTED_TARGET = "testendpoint.google.com:443"
6975
assert (client._transport.grpc_channel._channel.target()).decode(
7076
"utf-8"
71-
) == "testendpoint.google.com:443"
77+
) == _EXPECTED_TARGET
7278

7379

7480
def test_init_w_empty_client_options(creds):
7581
client = subscriber.Client(client_options={}, credentials=creds)
76-
82+
# Behavior to include dns prefix changed in gRPCv1.63
83+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
84+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
85+
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
86+
else:
87+
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
7788
assert (client._transport.grpc_channel._channel.target()).decode(
7889
"utf-8"
79-
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS
90+
) == _EXPECTED_TARGET
8091

8192

8293
def test_init_client_options_pass_through():
@@ -115,7 +126,13 @@ def test_init_emulator(monkeypatch):
115126
# Sadly, there seems to be no good way to do this without poking at
116127
# the private API of gRPC.
117128
channel = client._transport.pull._channel
118-
assert channel.target().decode("utf8") == "/baz/bacon:123"
129+
# Behavior to include dns prefix changed in gRPCv1.63
130+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
131+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
132+
_EXPECTED_TARGET = "dns:////baz/bacon:123"
133+
else:
134+
_EXPECTED_TARGET = "/baz/bacon:123"
135+
assert channel.target().decode("utf8") == _EXPECTED_TARGET
119136

120137

121138
def test_class_method_factory():

0 commit comments

Comments
 (0)