Skip to content

Commit

Permalink
fix: Test failures due to grpcio changes
Browse files Browse the repository at this point in the history
* Failures can be found in googleapis/python-api-common-protos#223
  • Loading branch information
mukund-ananthu committed May 29, 2024
1 parent ff229a5 commit fda43e0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
30 changes: 22 additions & 8 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,31 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = publisher.Client(client_options=client_options, credentials=creds)

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


def test_init_w_empty_client_options(creds):
client = publisher.Client(client_options={}, credentials=creds)

assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == publisher_client.PublisherClient.SERVICE_ADDRESS

# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "dns:///pubsub.googleapis.com:443"
else:
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "pubsub.googleapis.com:443"


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -182,7 +196,7 @@ def test_init_emulator(monkeypatch):
# Sadly, there seems to be no good way to do this without poking at
# the private API of gRPC.
channel = client._transport.publish._channel
assert channel.target().decode("utf8") == "/foo/bar:123"
assert channel.target().decode("utf8") == "dns:////foo/bar:123"


def test_message_ordering_enabled(creds):
Expand Down
36 changes: 28 additions & 8 deletions tests/unit/pubsub_v1/subscriber/test_subscriber_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,32 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = subscriber.Client(client_options=client_options, credentials=creds)

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


def test_init_w_empty_client_options(creds):
client = subscriber.Client(client_options={}, credentials=creds)

assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS


# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "dns:///pubsub.googleapis.com:443"
else:
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "pubsub.googleapis.com:443"


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -115,7 +130,12 @@ def test_init_emulator(monkeypatch):
# Sadly, there seems to be no good way to do this without poking at
# the private API of gRPC.
channel = client._transport.pull._channel
assert channel.target().decode("utf8") == "/baz/bacon:123"
# Behavior to include dns prefix changed in gRPCv1.63
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
assert channel.target().decode("utf8") == "dns:////baz/bacon:123"
else:
assert channel.target().decode("utf8") == "baz/bacon:123"


def test_class_method_factory():
Expand Down

0 comments on commit fda43e0

Please sign in to comment.