Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions google/cloud/pubsublite/internal/wire/reset_signal.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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