Skip to content

Commit

Permalink
Merge pull request grpc#7272 from nathanielmanistaatgoogle/rendezvous…
Browse files Browse the repository at this point in the history
…-exception

Fix _Rendezvous.exception for successful calls
  • Loading branch information
kpayson64 committed Jul 8, 2016
2 parents 32d3fbe + 4dd9ca9 commit acb0207
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/python/grpcio/grpc/beta/_client_adaptations.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def result(self, timeout=None):
def exception(self, timeout=None):
try:
rpc_error_call = self._future.exception(timeout=timeout)
return _abortion_error(rpc_error_call)
if rpc_error_call is None:
return None
else:
return _abortion_error(rpc_error_call)
except grpc.FutureTimeoutError:
raise future.TimeoutError()
except grpc.FutureCancelledError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import six

# test_interfaces is referenced from specification in this module.
from grpc.framework.foundation import future
from grpc.framework.foundation import logging_pool
from grpc.framework.interfaces.face import face
from tests.unit.framework.common import test_constants
Expand Down Expand Up @@ -159,6 +160,8 @@ def testSuccessfulUnaryRequestUnaryResponse(self):

test_messages.verify(request, response, self)
self.assertIs(callback.future(), response_future)
self.assertIsNone(response_future.exception())
self.assertIsNone(response_future.traceback())

def testSuccessfulUnaryRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -191,6 +194,8 @@ def testSuccessfulStreamRequestUnaryResponse(self):

test_messages.verify(requests, response, self)
self.assertIs(future_passed_to_callback, response_future)
self.assertIsNone(response_future.exception())
self.assertIsNone(response_future.traceback())

def testSuccessfulStreamRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -301,6 +306,12 @@ def testCancelledUnaryRequestUnaryResponse(self):
self.assertIs(callback.future(), response_future)
self.assertFalse(cancel_method_return_value)
self.assertTrue(response_future.cancelled())
with self.assertRaises(future.CancelledError):
response_future.result()
with self.assertRaises(future.CancelledError):
response_future.exception()
with self.assertRaises(future.CancelledError):
response_future.traceback()

def testCancelledUnaryRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -332,6 +343,12 @@ def testCancelledStreamRequestUnaryResponse(self):
self.assertIs(callback.future(), response_future)
self.assertFalse(cancel_method_return_value)
self.assertTrue(response_future.cancelled())
with self.assertRaises(future.CancelledError):
response_future.result()
with self.assertRaises(future.CancelledError):
response_future.exception()
with self.assertRaises(future.CancelledError):
response_future.traceback()

def testCancelledStreamRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -363,6 +380,9 @@ def testExpiredUnaryRequestUnaryResponse(self):
response_future.exception(), face.ExpirationError)
with self.assertRaises(face.ExpirationError):
response_future.result()
self.assertIsInstance(
response_future.exception(), face.AbortionError)
self.assertIsNotNone(response_future.traceback())

def testExpiredUnaryRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -392,6 +412,9 @@ def testExpiredStreamRequestUnaryResponse(self):
response_future.exception(), face.ExpirationError)
with self.assertRaises(face.ExpirationError):
response_future.result()
self.assertIsInstance(
response_future.exception(), face.AbortionError)
self.assertIsNotNone(response_future.traceback())

def testExpiredStreamRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -426,6 +449,7 @@ def testFailedUnaryRequestUnaryResponse(self):
response_future.exception(), face.ExpirationError)
with self.assertRaises(face.ExpirationError):
response_future.result()
self.assertIsNotNone(response_future.traceback())

def testFailedUnaryRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down Expand Up @@ -463,6 +487,7 @@ def testFailedStreamRequestUnaryResponse(self):
response_future.exception(), face.ExpirationError)
with self.assertRaises(face.ExpirationError):
response_future.result()
self.assertIsNotNone(response_future.traceback())

def testFailedStreamRequestStreamResponse(self):
for (group, method), test_messages_sequence in (
Expand Down

0 comments on commit acb0207

Please sign in to comment.