Skip to content

Commit ddc98d4

Browse files
committed
Add GatewayTimeout exception to pubsub subscription pull.
1 parent f6f02f6 commit ddc98d4

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

core/google/cloud/_testing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def _make_grpc_failed_precondition(self):
7777
from grpc import StatusCode
7878
return self._make_grpc_error(StatusCode.FAILED_PRECONDITION)
7979

80+
def _make_grpc_deadline_exceeded(self):
81+
from grpc import StatusCode
82+
return self._make_grpc_error(StatusCode.DEADLINE_EXCEEDED)
83+
8084

8185
class _GAXPageIterator(object):
8286

pubsub/google/cloud/pubsub/_gax.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from google.cloud._helpers import make_secure_channel
3434
from google.cloud._http import DEFAULT_USER_AGENT
3535
from google.cloud.exceptions import Conflict
36+
from google.cloud.exceptions import GatewayTimeout
3637
from google.cloud.exceptions import NotFound
3738
from google.cloud.iterator import GAXIterator
3839
from google.cloud.pubsub._helpers import subscription_name_from_path
@@ -415,6 +416,8 @@ def subscription_pull(self, subscription_path, return_immediately=False,
415416
except GaxError as exc:
416417
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
417418
raise NotFound(subscription_path)
419+
if exc_to_code(exc.cause) == StatusCode.DEADLINE_EXCEEDED:
420+
raise GatewayTimeout(subscription_path)
418421
raise
419422
return [_received_message_pb_to_mapping(rmpb)
420423
for rmpb in response_pb.received_messages]

pubsub/unit_tests/test__gax.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,14 @@ def test_subscription_pull_defaults_error(self):
764764
self.assertFalse(return_immediately)
765765
self.assertIsNone(options)
766766

767+
def test_subscription_pull_deadline_exceeded(self):
768+
from google.cloud.exceptions import GatewayTimeout
769+
gax_api = _GAXSubscriberAPI(_deadline_exceeded_gax_error=True)
770+
api = self._makeOne(gax_api)
771+
772+
with self.assertRaises(GatewayTimeout):
773+
api.subscription_pull(self.SUB_PATH)
774+
767775
def test_subscription_acknowledge_hit(self):
768776
ACK_ID1 = 'DEADBEEF'
769777
ACK_ID2 = 'BEADCAFE'
@@ -1075,6 +1083,7 @@ class _GAXSubscriberAPI(_GAXBaseAPI):
10751083
_modify_push_config_ok = False
10761084
_acknowledge_ok = False
10771085
_modify_ack_deadline_ok = False
1086+
_deadline_exceeded_gax_error = False
10781087

10791088
def list_subscriptions(self, project, page_size, options=None):
10801089
self._list_subscriptions_called_with = (project, page_size, options)
@@ -1124,6 +1133,9 @@ def pull(self, name, max_messages, return_immediately, options=None):
11241133
name, max_messages, return_immediately, options)
11251134
if self._random_gax_error:
11261135
raise GaxError('error')
1136+
if self._deadline_exceeded_gax_error:
1137+
raise GaxError('deadline exceeded',
1138+
self._make_grpc_deadline_exceeded())
11271139
try:
11281140
return self._pull_response
11291141
except AttributeError:

0 commit comments

Comments
 (0)