Skip to content

Commit

Permalink
fix: is_reset_signal should handle status that is None (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdiep committed Jul 13, 2021
1 parent e8378f2 commit 4ba484e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
17 changes: 10 additions & 7 deletions google/cloud/pubsublite/internal/wire/reset_signal.py
Expand Up @@ -29,14 +29,17 @@ def is_reset_signal(error: GoogleAPICallError) -> bool:
return False
try:
status = rpc_status.from_call(error.response)
if not status:
return False
for detail in status.details:
info = ErrorInfo()
if (
detail.Unpack(info)
and info.reason == "RESET"
and info.domain == "pubsublite.googleapis.com"
):
return True
if detail.Is(ErrorInfo.DESCRIPTOR):
info = ErrorInfo()
if (
detail.Unpack(info)
and info.reason == "RESET"
and info.domain == "pubsublite.googleapis.com"
):
return True
except ValueError:
pass
return False
7 changes: 7 additions & 0 deletions google/cloud/pubsublite/testing/test_reset_signal.py
Expand Up @@ -30,6 +30,13 @@ def make_call(status_pb: Status) -> grpc.Call:
return mock_call


def make_call_without_metadata(status_pb: Status) -> grpc.Call:
mock_call = make_call(status_pb)
# Causes rpc_status.from_call to return None.
mock_call.trailing_metadata.return_value = None
return mock_call


def make_reset_signal() -> GoogleAPICallError:
any = Any()
any.Pack(ErrorInfo(reason="RESET", domain="pubsublite.googleapis.com"))
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/pubsublite/internal/wire/reset_signal_test.py
Expand Up @@ -17,6 +17,7 @@
from google.cloud.pubsublite.internal.wire.reset_signal import is_reset_signal
from google.cloud.pubsublite.testing.test_reset_signal import (
make_call,
make_call_without_metadata,
make_reset_signal,
)
from google.protobuf.any_pb2 import Any
Expand All @@ -39,6 +40,13 @@ async def test_missing_call():
assert not is_reset_signal(Aborted(""))


async def test_extracted_status_is_none():
status_pb = Status(code=10, details=[])
assert not is_reset_signal(
Aborted("", response=make_call_without_metadata(status_pb))
)


async def test_wrong_reason():
any = Any()
any.Pack(ErrorInfo(reason="OTHER", domain="pubsublite.googleapis.com"))
Expand Down

0 comments on commit 4ba484e

Please sign in to comment.