Fix the tests after merging with Unified Stub Call

pull/20805/head
Lidi Zheng 5 years ago
parent ae59fc3b7a
commit 4373d88caf
  1. 2
      src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi
  2. 3
      src/python/grpcio/grpc/experimental/aio/__init__.py
  3. 39
      src/python/grpcio_tests/tests_aio/unit/init_test.py
  4. 25
      src/python/grpcio_tests/tests_aio/unit/server_test.py

@ -64,7 +64,7 @@ cdef class CallbackWrapper:
grpc_experimental_completion_queue_functor* functor,
int success):
cdef CallbackContext *context = <CallbackContext *>functor
if succeed == 0:
if success == 0:
(<_CallbackFailureHandler>context.failure_handler).handle(
<object>context.waiter)
else:

@ -17,11 +17,8 @@ import abc
import six
import grpc
<<<<<<< HEAD
=======
from grpc import _common
from grpc._cython import cygrpc
>>>>>>> Add 4 server tests and 1 channel tests
from grpc._cython.cygrpc import init_grpc_aio
from ._call import AioRpcError

@ -19,45 +19,6 @@ from tests_aio.unit._test_server import start_test_server
from tests_aio.unit._test_base import AioTestBase
class TestAioRpcError(unittest.TestCase):
_TEST_INITIAL_METADATA = ("initial metadata",)
_TEST_TRAILING_METADATA = ("trailing metadata",)
def test_attributes(self):
aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
"details", self._TEST_TRAILING_METADATA)
self.assertEqual(aio_rpc_error.initial_metadata(),
self._TEST_INITIAL_METADATA)
self.assertEqual(aio_rpc_error.code(), grpc.StatusCode.OK)
self.assertEqual(aio_rpc_error.details(), "details")
self.assertEqual(aio_rpc_error.trailing_metadata(),
self._TEST_TRAILING_METADATA)
def test_class_hierarchy(self):
aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
"details", self._TEST_TRAILING_METADATA)
self.assertIsInstance(aio_rpc_error, grpc.RpcError)
def test_class_attributes(self):
aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
"details", self._TEST_TRAILING_METADATA)
self.assertEqual(aio_rpc_error.__class__.__name__, "AioRpcError")
self.assertEqual(aio_rpc_error.__class__.__doc__,
aio.AioRpcError.__doc__)
def test_class_singleton(self):
first_aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
"details",
self._TEST_TRAILING_METADATA)
second_aio_rpc_error = aio.AioRpcError(self._TEST_INITIAL_METADATA, 0,
"details",
self._TEST_TRAILING_METADATA)
self.assertIs(first_aio_rpc_error.__class__,
second_aio_rpc_error.__class__)
class TestInsecureChannel(AioTestBase):
def test_insecure_channel(self):

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import logging
import unittest
import time
@ -110,8 +111,7 @@ class TestServer(AioTestBase):
server_target, server, generic_handler = await _start_test_server()
channel = aio.insecure_channel(server_target)
call_task = self.loop.create_task(
channel.unary_unary(_BLOCK_BRIEFLY)(_REQUEST))
call = channel.unary_unary(_BLOCK_BRIEFLY)(_REQUEST)
await generic_handler.wait_for_call()
shutdown_start_time = time.time()
@ -122,8 +122,8 @@ class TestServer(AioTestBase):
# Validates the states.
await channel.close()
self.assertEqual(_RESPONSE, await call_task)
self.assertTrue(call_task.done())
self.assertEqual(_RESPONSE, await call)
self.assertTrue(call.done())
self.loop.run_until_complete(test_graceful_shutdown_success_body())
@ -133,14 +133,13 @@ class TestServer(AioTestBase):
server_target, server, generic_handler = await _start_test_server()
channel = aio.insecure_channel(server_target)
call_task = self.loop.create_task(
channel.unary_unary(_BLOCK_FOREVER)(_REQUEST))
call = channel.unary_unary(_BLOCK_FOREVER)(_REQUEST)
await generic_handler.wait_for_call()
await server.stop(test_constants.SHORT_TIMEOUT)
with self.assertRaises(aio.AioRpcError) as exception_context:
await call_task
await call
self.assertEqual(grpc.StatusCode.UNAVAILABLE,
exception_context.exception.code())
self.assertIn('GOAWAY', exception_context.exception.details())
@ -154,8 +153,7 @@ class TestServer(AioTestBase):
server_target, server, generic_handler = await _start_test_server()
channel = aio.insecure_channel(server_target)
call_task = self.loop.create_task(
channel.unary_unary(_BLOCK_BRIEFLY)(_REQUEST))
call = channel.unary_unary(_BLOCK_BRIEFLY)(_REQUEST)
await generic_handler.wait_for_call()
# Expects the shortest grace period to be effective.
@ -170,8 +168,8 @@ class TestServer(AioTestBase):
test_constants.SHORT_TIMEOUT / 3)
await channel.close()
self.assertEqual(_RESPONSE, await call_task)
self.assertTrue(call_task.done())
self.assertEqual(_RESPONSE, await call)
self.assertTrue(call.done())
self.loop.run_until_complete(test_concurrent_graceful_shutdown_body())
@ -181,8 +179,7 @@ class TestServer(AioTestBase):
server_target, server, generic_handler = await _start_test_server()
channel = aio.insecure_channel(server_target)
call_task = self.loop.create_task(
channel.unary_unary(_BLOCK_FOREVER)(_REQUEST))
call = channel.unary_unary(_BLOCK_FOREVER)(_REQUEST)
await generic_handler.wait_for_call()
# Expects no grace period, due to the "server.stop(None)".
@ -194,7 +191,7 @@ class TestServer(AioTestBase):
)
with self.assertRaises(aio.AioRpcError) as exception_context:
await call_task
await call
self.assertEqual(grpc.StatusCode.UNAVAILABLE,
exception_context.exception.code())
self.assertIn('GOAWAY', exception_context.exception.details())

Loading…
Cancel
Save