Supply the event loop to aio iomgr in test case level

pull/20771/head
Lidi Zheng 6 years ago
parent dcf609966e
commit 70821ebe4a
  1. 2
      src/python/grpcio_tests/commands.py
  2. 7
      src/python/grpcio_tests/tests_aio/unit/BUILD.bazel
  3. 9
      src/python/grpcio_tests/tests_aio/unit/channel_test.py

@ -119,8 +119,6 @@ class TestAio(setuptools.Command):
pass pass
def run(self): def run(self):
from grpc.experimental import aio
aio.init_grpc_aio()
self._add_eggs_to_path() self._add_eggs_to_path()
import tests import tests

@ -20,6 +20,12 @@ package(
GRPC_ASYNC_TESTS = glob(["*_test.py"]) GRPC_ASYNC_TESTS = glob(["*_test.py"])
py_library(
name = "_test_base",
srcs_version = "PY3",
srcs = ["_test_base.py"],
)
py_library( py_library(
name = "_test_server", name = "_test_server",
srcs_version = "PY3", srcs_version = "PY3",
@ -41,6 +47,7 @@ py_library(
python_version="PY3", python_version="PY3",
deps=[ deps=[
":_test_server", ":_test_server",
":_test_base",
"//src/python/grpcio/grpc:grpcio", "//src/python/grpcio/grpc:grpcio",
"//src/proto/grpc/testing:py_messages_proto", "//src/proto/grpc/testing:py_messages_proto",
"//src/proto/grpc/testing:benchmark_service_py_pb2_grpc", "//src/proto/grpc/testing:benchmark_service_py_pb2_grpc",

@ -22,9 +22,10 @@ from grpc.experimental import aio
from src.proto.grpc.testing import messages_pb2 from src.proto.grpc.testing import messages_pb2
from tests.unit.framework.common import test_constants from tests.unit.framework.common import test_constants
from tests_aio.unit._test_server import start_test_server from tests_aio.unit._test_server import start_test_server
from tests_aio.unit._test_base import AioTestBase
class TestChannel(unittest.TestCase): class TestChannel(AioTestBase):
def test_async_context(self): def test_async_context(self):
@ -40,7 +41,7 @@ class TestChannel(unittest.TestCase):
) )
await hi(messages_pb2.SimpleRequest()) await hi(messages_pb2.SimpleRequest())
asyncio.get_event_loop().run_until_complete(coro()) self._loop.run_until_complete(coro())
def test_unary_unary(self): def test_unary_unary(self):
@ -58,7 +59,7 @@ class TestChannel(unittest.TestCase):
await channel.close() await channel.close()
asyncio.get_event_loop().run_until_complete(coro()) self._loop.run_until_complete(coro())
def test_unary_call_times_out(self): def test_unary_call_times_out(self):
@ -90,7 +91,7 @@ class TestChannel(unittest.TestCase):
self.assertIsNotNone( self.assertIsNotNone(
exception_context.exception.trailing_metadata()) exception_context.exception.trailing_metadata())
asyncio.get_event_loop().run_until_complete(coro()) self._loop.run_until_complete(coro())
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save