27 _UNARY_UNARY_ABORT =
'/test/UnaryUnaryAbort'
28 _SUPPRESS_ABORT =
'/test/SuppressAbort'
29 _REPLACE_ABORT =
'/test/ReplaceAbort'
30 _ABORT_AFTER_REPLY =
'/test/AbortAfterReply'
32 _REQUEST = b
'\x00\x00\x00'
33 _RESPONSE = b
'\x01\x01\x01'
34 _NUM_STREAM_RESPONSES = 5
36 _ABORT_CODE = grpc.StatusCode.RESOURCE_EXHAUSTED
37 _ABORT_DETAILS =
'Phony error details'
44 await context.abort(_ABORT_CODE, _ABORT_DETAILS)
45 raise RuntimeError(
'This line should not be executed')
48 async
def _suppress_abort(unused_request, context):
50 await context.abort(_ABORT_CODE, _ABORT_DETAILS)
51 except aio.AbortError
as e:
56 async
def _replace_abort(unused_request, context):
58 await context.abort(_ABORT_CODE, _ABORT_DETAILS)
59 except aio.AbortError
as e:
60 await context.abort(grpc.StatusCode.INVALID_ARGUMENT,
64 async
def _abort_after_reply(unused_request, context):
66 await context.abort(_ABORT_CODE, _ABORT_DETAILS)
67 raise RuntimeError(
'This line should not be executed')
69 def service(self, handler_details):
70 if handler_details.method == _UNARY_UNARY_ABORT:
72 if handler_details.method == _SUPPRESS_ABORT:
74 if handler_details.method == _REPLACE_ABORT:
76 if handler_details.method == _ABORT_AFTER_REPLY:
82 port = server.add_insecure_port(
'[::]:0')
85 return 'localhost:%d' % port, server
94 async
def tearDown(self):
98 async
def test_unary_unary_abort(self):
102 self.assertEqual(_ABORT_CODE, await call.code())
103 self.assertEqual(_ABORT_DETAILS, await call.details())
105 with self.assertRaises(aio.AioRpcError)
as exception_context:
108 rpc_error = exception_context.exception
109 self.assertEqual(_ABORT_CODE, rpc_error.code())
110 self.assertEqual(_ABORT_DETAILS, rpc_error.details())
112 async
def test_suppress_abort(self):
116 with self.assertRaises(aio.AioRpcError)
as exception_context:
119 rpc_error = exception_context.exception
120 self.assertEqual(_ABORT_CODE, rpc_error.code())
121 self.assertEqual(_ABORT_DETAILS, rpc_error.details())
123 async
def test_replace_abort(self):
127 with self.assertRaises(aio.AioRpcError)
as exception_context:
130 rpc_error = exception_context.exception
131 self.assertEqual(_ABORT_CODE, rpc_error.code())
132 self.assertEqual(_ABORT_DETAILS, rpc_error.details())
134 async
def test_abort_after_reply(self):
138 with self.assertRaises(aio.AioRpcError)
as exception_context:
142 rpc_error = exception_context.exception
143 self.assertEqual(_ABORT_CODE, rpc_error.code())
144 self.assertEqual(_ABORT_DETAILS, rpc_error.details())
146 self.assertEqual(_ABORT_CODE, await call.code())
147 self.assertEqual(_ABORT_DETAILS, await call.details())
150 if __name__ ==
'__main__':
151 logging.basicConfig(level=logging.DEBUG)
152 unittest.main(verbosity=2)