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
2 changes: 1 addition & 1 deletion pubsub/google/cloud/pubsub_v1/publisher/_batch/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _commit(self):

try:
response = self._client.api.publish(self._topic, self._messages)
except google.api_core.exceptions.GoogleAPICallError as exc:
except google.api_core.exceptions.GoogleAPIError as exc:
# We failed to publish, set the exception on all futures and
# exit.
self._status = base.BatchStatus.ERROR
Expand Down
19 changes: 19 additions & 0 deletions pubsub/tests/unit/pubsub_v1/publisher/batch/test_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ def test_block__commmit_api_error():
assert future.exception() == error


def test_block__commmit_retry_error():
batch = create_batch()
futures = (
batch.publish({"data": b"blah blah blah"}),
batch.publish({"data": b"blah blah blah blah"}),
)

# Make the API throw an error when publishing.
error = google.api_core.exceptions.RetryError("uh oh", None)
patch = mock.patch.object(type(batch.client.api), "publish", side_effect=error)

with patch:
batch._commit()

for future in futures:
assert future.done()
assert future.exception() == error


def test_monitor():
batch = create_batch(max_latency=5.0)
with mock.patch.object(time, "sleep") as sleep:
Expand Down