[WIP] Feedback on the PR

pull/22343/head
Mariano Anaya 5 years ago committed by Lidi Zheng
parent a3459d371d
commit 33e15156bb
  1. 2
      src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi
  2. 7
      src/python/grpcio/grpc/experimental/aio/_call.py
  3. 8
      src/python/grpcio_tests/tests_aio/tests.json
  4. 7
      src/python/grpcio_tests/tests_aio/unit/_test_server.py
  5. 45
      src/python/grpcio_tests/tests_aio/unit/call_test.py
  6. 28
      src/python/grpcio_tests/tests_aio/unit/init_test.py
  7. 51
      src/python/grpcio_tests/tests_aio/unit/secure_call_test.py

@ -125,7 +125,7 @@ cdef class _AioCall(GrpcCallWrapper):
if credentials is not None:
set_credentials_error = grpc_call_set_credentials(self.call, credentials.c())
if set_credentials_error != GRPC_CALL_OK:
raise RuntimeError(f"Credentials couldn't have been set: {set_credentials_error}")
raise RuntimeError("Credentials couldn't have been set: {0}".format(set_credentials_error))
grpc_slice_unref(method_slice)

@ -281,13 +281,8 @@ class _UnaryResponseMixin(Call):
if self._cython_call.is_locally_cancelled():
raise asyncio.CancelledError()
else:
call_status = self._cython_call._status
debug_error_string = ""
if call_status is not None:
debug_error_string = call_status._debug_error_string
raise _create_rpc_error(self._cython_call._initial_metadata,
call_status,
debug_error_string)
self._cython_call._status)
else:
return response

@ -9,7 +9,6 @@
"unit.call_test.TestStreamUnaryCall",
"unit.call_test.TestUnaryStreamCall",
"unit.call_test.TestUnaryUnaryCall",
"unit.call_test.TestUnaryUnarySecureCall",
"unit.channel_argument_test.TestChannelArgument",
"unit.channel_ready_test.TestChannelReady",
"unit.channel_test.TestChannel",
@ -20,10 +19,11 @@
"unit.compression_test.TestCompression",
"unit.connectivity_test.TestConnectivityState",
"unit.done_callback_test.TestDoneCallback",
"unit.init_test.TestInsecureChannel",
"unit.init_test.TestSecureChannel",
"unit.init_test.TestChannel",
"unit.interceptor_test.TestInterceptedUnaryUnaryCall",
"unit.interceptor_test.TestUnaryUnaryClientInterceptor",
"unit.metadata_test.TestMetadata",
"unit.server_interceptor_test.TestServerInterceptor",
"unit.secure_call_test.TestUnaryUnarySecureCall",
"unit.server_test.TestServer",
"unit.timeout_test.TestTimeout",
"unit.wait_for_ready_test.TestWaitForReady"

@ -130,8 +130,9 @@ async def start_test_server(port=0,
if secure:
if server_credentials is None:
server_credentials = grpc.local_server_credentials(
grpc.LocalConnectionType.LOCAL_TCP)
server_credentials = grpc.ssl_server_credentials([
(resources.private_key(), resources.certificate_chain())
])
port = server.add_secure_port('[::]:%d' % port, server_credentials)
else:
port = server.add_insecure_port('[::]:%d' % port)
@ -139,4 +140,4 @@ async def start_test_server(port=0,
await server.start()
# NOTE(lidizheng) returning the server to prevent it from deallocation
return '0.0.0.0:%d' % port, server
return 'localhost:%d' % port, server

@ -34,7 +34,6 @@ _LOCAL_CANCEL_DETAILS_EXPECTATION = 'Locally cancelled by application!'
_RESPONSE_INTERVAL_US = test_constants.SHORT_TIMEOUT * 1000 * 1000
_UNREACHABLE_TARGET = '0.1:1111'
_INFINITE_INTERVAL_US = 2**31 - 1
_SERVER_HOST_OVERRIDE = 'foo.test.google.fr'
class _MulticallableTestMixin():
@ -49,33 +48,6 @@ class _MulticallableTestMixin():
await self._server.stop(None)
class _SecureCallMixin:
"""A Mixin to run the call tests over a secure channel."""
async def setUp(self):
server_credentials = grpc.ssl_server_credentials([
(resources.private_key(), resources.certificate_chain())
])
channel_credentials = grpc.ssl_channel_credentials(
resources.test_root_certificates())
self._server_address, self._server = await start_test_server(
secure=True, server_credentials=server_credentials)
channel_options = (
(
'grpc.ssl_target_name_override',
_SERVER_HOST_OVERRIDE,
),
)
self._channel = aio.secure_channel(self._server_address, channel_credentials, channel_options)
self._stub = test_pb2_grpc.TestServiceStub(self._channel)
async def tearDown(self):
await self._channel.close()
await self._server.stop(None)
class TestUnaryUnaryCall(_MulticallableTestMixin, AioTestBase):
async def test_call_to_string(self):
@ -236,17 +208,11 @@ class TestUnaryUnaryCall(_MulticallableTestMixin, AioTestBase):
grpc.access_token_call_credentials("abc"),
grpc.access_token_call_credentials("def"),
)
with self.assertRaisesRegex(RuntimeError, "Call credentials are only valid on secure channels"):
self._stub.UnaryCall(messages_pb2.SimpleRequest(), credentials=call_credentials)
class TestUnaryUnarySecureCall(_SecureCallMixin, AioTestBase):
"""Calls made over a secure channel."""
async def test_call_ok_with_credentials(self):
call = self._stub.UnaryCall(messages_pb2.SimpleRequest())
response = await call
self.assertIsInstance(response, messages_pb2.SimpleResponse)
self.assertEqual(await call.code(), grpc.StatusCode.OK)
with self.assertRaisesRegex(
RuntimeError,
"Call credentials are only valid on secure channels"):
self._stub.UnaryCall(messages_pb2.SimpleRequest(),
credentials=call_credentials)
class TestUnaryStreamCall(_MulticallableTestMixin, AioTestBase):
@ -601,6 +567,7 @@ _STREAM_OUTPUT_REQUEST_ONE_RESPONSE.response_parameters.append(
class TestStreamStreamCall(_MulticallableTestMixin, AioTestBase):
async def test_cancel(self):
# Invokes the actual RPC
call = self._stub.FullDuplexCall()

@ -27,7 +27,7 @@ _CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
class TestInsecureChannel(AioTestBase):
class TestChannel(AioTestBase):
async def test_insecure_channel(self):
server_target, _ = await start_test_server() # pylint: disable=unused-variable
@ -35,24 +35,16 @@ class TestInsecureChannel(AioTestBase):
channel = aio.insecure_channel(server_target)
self.assertIsInstance(channel, aio.Channel)
async def tests_secure_channel(self):
server_target, _ = await start_test_server(secure=True) # pylint: disable=unused-variable
credentials = grpc.ssl_channel_credentials(
root_certificates=_TEST_ROOT_CERTIFICATES,
private_key=_PRIVATE_KEY,
certificate_chain=_CERTIFICATE_CHAIN,
)
secure_channel = aio.secure_channel(server_target, credentials)
class TestSecureChannel(AioTestBase):
"""Test a secure channel connected to a secure server"""
def test_secure_channel(self):
async def coro():
server_target, _ = await start_test_server(secure=True) # pylint: disable=unused-variable
credentials = grpc.ssl_channel_credentials(
root_certificates=_TEST_ROOT_CERTIFICATES,
private_key=_PRIVATE_KEY,
certificate_chain=_CERTIFICATE_CHAIN,
)
secure_channel = aio.secure_channel(server_target, credentials)
self.assertIsInstance(secure_channel, aio.Channel)
self.loop.run_until_complete(coro())
self.assertIsInstance(secure_channel, aio.Channel)
if __name__ == '__main__':

@ -0,0 +1,51 @@
import unittest
import logging
import grpc
from grpc.experimental import aio
from src.proto.grpc.testing import messages_pb2, test_pb2_grpc
from tests_aio.unit._test_base import AioTestBase
from tests_aio.unit._test_server import start_test_server
from tests.unit import resources
_SERVER_HOST_OVERRIDE = 'foo.test.google.fr'
class _SecureCallMixin:
"""A Mixin to run the call tests over a secure channel."""
async def setUp(self):
server_credentials = grpc.ssl_server_credentials([
(resources.private_key(), resources.certificate_chain())
])
channel_credentials = grpc.ssl_channel_credentials(
resources.test_root_certificates())
self._server_address, self._server = await start_test_server(
secure=True, server_credentials=server_credentials)
channel_options = ((
'grpc.ssl_target_name_override',
_SERVER_HOST_OVERRIDE,
),)
self._channel = aio.secure_channel(self._server_address,
channel_credentials, channel_options)
self._stub = test_pb2_grpc.TestServiceStub(self._channel)
async def tearDown(self):
await self._channel.close()
await self._server.stop(None)
class TestUnaryUnarySecureCall(_SecureCallMixin, AioTestBase):
"""Calls made over a secure channel."""
async def test_call_ok_with_credentials(self):
call = self._stub.UnaryCall(messages_pb2.SimpleRequest())
response = await call
self.assertIsInstance(response, messages_pb2.SimpleResponse)
self.assertEqual(await call.code(), grpc.StatusCode.OK)
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)
Loading…
Cancel
Save