Skip to content

Commit

Permalink
fix: Test failures due to grpcio changes (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukund-ananthu committed May 30, 2024
1 parent ff229a5 commit 086dd46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
25 changes: 21 additions & 4 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,28 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = publisher.Client(client_options=client_options, credentials=creds)

# 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):
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
else:
_EXPECTED_TARGET = "testendpoint.google.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "testendpoint.google.com:443"
) == _EXPECTED_TARGET


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

# 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):
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
else:
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == publisher_client.PublisherClient.SERVICE_ADDRESS
) == _EXPECTED_TARGET


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -182,7 +193,13 @@ 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"
# 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):
_EXPECTED_TARGET = "dns:////foo/bar:123"
else:
_EXPECTED_TARGET = "/foo/bar:123"
assert channel.target().decode("utf8") == _EXPECTED_TARGET


def test_message_ordering_enabled(creds):
Expand Down
25 changes: 21 additions & 4 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,28 @@ def test_init_w_api_endpoint(creds):
client_options = {"api_endpoint": "testendpoint.google.com"}
client = subscriber.Client(client_options=client_options, credentials=creds)

# 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):
_EXPECTED_TARGET = "dns:///testendpoint.google.com:443"
else:
_EXPECTED_TARGET = "testendpoint.google.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == "testendpoint.google.com:443"
) == _EXPECTED_TARGET


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

# 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):
_EXPECTED_TARGET = "dns:///pubsub.googleapis.com:443"
else:
_EXPECTED_TARGET = "pubsub.googleapis.com:443"
assert (client._transport.grpc_channel._channel.target()).decode(
"utf-8"
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS
) == _EXPECTED_TARGET


def test_init_client_options_pass_through():
Expand Down Expand Up @@ -115,7 +126,13 @@ 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):
_EXPECTED_TARGET = "dns:////baz/bacon:123"
else:
_EXPECTED_TARGET = "/baz/bacon:123"
assert channel.target().decode("utf8") == _EXPECTED_TARGET


def test_class_method_factory():
Expand Down

0 comments on commit 086dd46

Please sign in to comment.