From 349d79cae92d7da4b9a5d9bfdd055eb5fb07c7d3 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Mon, 28 Oct 2019 11:46:40 -0700 Subject: [PATCH] Integrate with asyncio tests --- .../grpcio_tests/tests_aio/unit/BUILD.bazel | 22 +++++++++++++++++++ .../grpcio_tests/tests_aio/unit/test_base.py | 16 +++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/python/grpcio_tests/tests_aio/unit/BUILD.bazel b/src/python/grpcio_tests/tests_aio/unit/BUILD.bazel index c6d0a9f7728..877337eb582 100644 --- a/src/python/grpcio_tests/tests_aio/unit/BUILD.bazel +++ b/src/python/grpcio_tests/tests_aio/unit/BUILD.bazel @@ -19,8 +19,27 @@ package( GRPC_ASYNC_TESTS = [ "server_test.py", + "init_test.py", + "channel_test.py", ] +py_library( + name = "test_base", + srcs = ["test_base.py"], + srcs_version = "PY3", +) + +py_library( + name = "sync_server", + srcs = ["sync_server.py"], + deps = [ + "//src/proto/grpc/testing:empty_py_pb2", + "//src/proto/grpc/testing:py_messages_proto", + "//src/proto/grpc/testing:test_py_pb2_grpc", + ], + srcs_version = "PY3", +) + [ py_test( name=test_file_name[:-3], @@ -33,6 +52,9 @@ GRPC_ASYNC_TESTS = [ "//src/proto/grpc/testing:py_messages_proto", "//src/proto/grpc/testing:benchmark_service_py_pb2_grpc", "//src/proto/grpc/testing:benchmark_service_py_pb2", + "//src/python/grpcio_tests/tests/unit/framework/common", + ":test_base", + ":sync_server", "//external:six" ], imports=["../../",], diff --git a/src/python/grpcio_tests/tests_aio/unit/test_base.py b/src/python/grpcio_tests/tests_aio/unit/test_base.py index 0b325523e0f..22c79e0f825 100644 --- a/src/python/grpcio_tests/tests_aio/unit/test_base.py +++ b/src/python/grpcio_tests/tests_aio/unit/test_base.py @@ -22,21 +22,11 @@ import socket from grpc.experimental import aio from tests_aio.unit import sync_server - +from tests.unit.framework.common import get_socket def _get_free_loopback_tcp_port(): - if socket.has_ipv6: - tcp_socket = socket.socket(socket.AF_INET6) - host = "::1" - host_target = "[::1]" - else: - tcp_socket = socket.socket(socket.AF_INET) - host = "127.0.0.1" - host_target = host - tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - tcp_socket.bind((host, 0)) - address_tuple = tcp_socket.getsockname() - return tcp_socket, "%s:%s" % (host_target, address_tuple[1]) + host, port, sock = get_socket(listen=False) + return sock, "{}:{}".format(host, port) class _Server: