|
|
|
@ -27,11 +27,10 @@ from tests_aio.unit._test_server import start_test_server |
|
|
|
|
from tests_aio.unit._test_base import AioTestBase |
|
|
|
|
|
|
|
|
|
_UNARY_CALL_METHOD = '/grpc.testing.TestService/UnaryCall' |
|
|
|
|
_EMPTY_CALL_METHOD = '/grpc.testing.TestService/EmptyCall' |
|
|
|
|
_STREAMING_OUTPUT_CALL_METHOD = '/grpc.testing.TestService/StreamingOutputCall' |
|
|
|
|
|
|
|
|
|
_NUM_STREAM_RESPONSES = 5 |
|
|
|
|
_RESPONSE_PAYLOAD_SIZE = 42 |
|
|
|
|
_UNREACHABLE_TARGET = '0.1:1111' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestChannel(AioTestBase): |
|
|
|
@ -62,21 +61,15 @@ class TestChannel(AioTestBase): |
|
|
|
|
self.assertIsInstance(response, messages_pb2.SimpleResponse) |
|
|
|
|
|
|
|
|
|
async def test_unary_call_times_out(self): |
|
|
|
|
async with aio.insecure_channel(self._server_target) as channel: |
|
|
|
|
empty_call_with_sleep = channel.unary_unary( |
|
|
|
|
_EMPTY_CALL_METHOD, |
|
|
|
|
async with aio.insecure_channel(_UNREACHABLE_TARGET) as channel: |
|
|
|
|
hi = channel.unary_unary( |
|
|
|
|
_UNARY_CALL_METHOD, |
|
|
|
|
request_serializer=messages_pb2.SimpleRequest.SerializeToString, |
|
|
|
|
response_deserializer=messages_pb2.SimpleResponse.FromString, |
|
|
|
|
) |
|
|
|
|
timeout = test_constants.SHORT_TIMEOUT / 2 |
|
|
|
|
# TODO(https://github.com/grpc/grpc/issues/20869) |
|
|
|
|
# Update once the async server is ready, change the |
|
|
|
|
# synchronization mechanism by removing the sleep(<timeout>) |
|
|
|
|
# as both components (client & server) will be on the same |
|
|
|
|
# process. |
|
|
|
|
|
|
|
|
|
with self.assertRaises(grpc.RpcError) as exception_context: |
|
|
|
|
await empty_call_with_sleep( |
|
|
|
|
messages_pb2.SimpleRequest(), timeout=timeout) |
|
|
|
|
await hi(messages_pb2.SimpleRequest(), timeout=1.0) |
|
|
|
|
|
|
|
|
|
_, details = grpc.StatusCode.DEADLINE_EXCEEDED.value # pylint: disable=unused-variable |
|
|
|
|
self.assertEqual(grpc.StatusCode.DEADLINE_EXCEEDED, |
|
|
|
@ -87,19 +80,6 @@ class TestChannel(AioTestBase): |
|
|
|
|
self.assertIsNotNone( |
|
|
|
|
exception_context.exception.trailing_metadata()) |
|
|
|
|
|
|
|
|
|
@unittest.skip('https://github.com/grpc/grpc/issues/20818') |
|
|
|
|
async def test_call_to_the_void(self): |
|
|
|
|
channel = aio.insecure_channel('0.1.1.1:1111') |
|
|
|
|
hi = channel.unary_unary( |
|
|
|
|
_UNARY_CALL_METHOD, |
|
|
|
|
request_serializer=messages_pb2.SimpleRequest.SerializeToString, |
|
|
|
|
response_deserializer=messages_pb2.SimpleResponse.FromString) |
|
|
|
|
response = await hi(messages_pb2.SimpleRequest()) |
|
|
|
|
|
|
|
|
|
self.assertIsInstance(response, messages_pb2.SimpleResponse) |
|
|
|
|
|
|
|
|
|
await channel.close() |
|
|
|
|
|
|
|
|
|
async def test_unary_stream(self): |
|
|
|
|
channel = aio.insecure_channel(self._server_target) |
|
|
|
|
stub = test_pb2_grpc.TestServiceStub(channel) |
|
|
|
@ -127,5 +107,5 @@ class TestChannel(AioTestBase): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
|
logging.basicConfig(level=logging.WARN) |
|
|
|
|
unittest.main(verbosity=2) |
|
|
|
|