@@ -221,6 +221,32 @@ def test_annotate_with_pb_requests_results(self):
221221 self .assertIsInstance (annotation , Annotations )
222222 gax_api ._annotator_client .batch_annotate_images .assert_called ()
223223
224+ def test_handle_retry_error (self ):
225+ from grpc ._channel import _Rendezvous
226+ from google .gax .errors import GaxError
227+ from google .gax .errors import RetryError
228+ from google .cloud .proto .vision .v1 import image_annotator_pb2
229+
230+ client = mock .Mock (spec_set = ['_credentials' ])
231+ request = image_annotator_pb2 .AnnotateImageRequest ()
232+
233+ # In the case of a RetryError being raised, we want to get to the root
234+ # exception. i.e. RetryError.cause.exception()
235+ mock_rendezvous = mock .Mock (spec = _Rendezvous )
236+ mock_rendezvous .exception .return_value = GaxError ('gax' )
237+
238+ with mock .patch ('google.cloud.vision._gax.image_annotator_client.'
239+ 'ImageAnnotatorClient' ):
240+ gax_api = self ._make_one (client )
241+
242+ gax_api ._annotator_client = mock .Mock (
243+ spec_set = ['batch_annotate_images' ])
244+
245+ gax_api ._annotator_client .batch_annotate_images = mock .Mock (
246+ side_effect = RetryError ('retry' , cause = mock_rendezvous ))
247+ with self .assertRaises (GaxError ):
248+ gax_api .annotate (requests_pb = [request ])
249+
224250
225251class Test__to_gapic_feature (unittest .TestCase ):
226252 def _call_fut (self , feature ):
0 commit comments