Make the test v4/v6 agnostic & fix some typo

pull/21607/head
Lidi Zheng 5 years ago
parent d1cf71ade5
commit d7698e7e1d
  1. 6
      src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi
  2. 2
      src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi
  3. 27
      src/python/grpcio_tests/tests_aio/unit/channel_argument_test.py

@ -122,11 +122,11 @@ cdef grpc_error* asyncio_socket_listen(grpc_custom_socket* grpc_socket) with gil
return grpc_error_none()
def _asyncio_apply_socket_options(object s):
def _asyncio_apply_socket_options(object socket):
# TODO(https://github.com/grpc/grpc/issues/20667)
# Connects the so_reuse_port option to channel arguments
s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1)
s.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True)
socket.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1)
socket.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True)
cdef grpc_error* asyncio_socket_bind(

@ -472,7 +472,7 @@ cdef class AioServer:
# TODO(lidiz) if users create server, and then dealloc it immediately.
# There is a potential memory leak of created Core server.
if self._status != AIO_SERVER_STATUS_STOPPED:
_LOGGER.warn(
_LOGGER.warning(
'__dealloc__ called on running server %s with status %d',
self,
self._status

@ -15,19 +15,17 @@
import asyncio
import logging
import unittest
import platform
import random
import socket
import unittest
import grpc
import random
from grpc.experimental import aio
from src.proto.grpc.testing import messages_pb2
from src.proto.grpc.testing import test_pb2_grpc
from tests.unit.framework.common import test_constants
from tests_aio.unit._test_server import start_test_server
from src.proto.grpc.testing import messages_pb2, test_pb2_grpc
from tests_aio.unit._test_base import AioTestBase
# 100 servers in sequence
from tests_aio.unit._test_server import start_test_server
_RANDOM_SEED = 42
@ -69,15 +67,18 @@ _INVALID_TEST_CHANNEL_ARGS = [
async def test_if_reuse_port_enabled(server: aio.Server):
port = server.add_insecure_port('127.0.0.1:0')
port = server.add_insecure_port('localhost:0')
await server.start()
try:
another_socket = socket.socket(family=socket.AF_INET)
if socket.has_ipv6:
another_socket = socket.socket(family=socket.AF_INET6)
else:
another_socket = socket.socket(family=socket.AF_INET)
another_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
another_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
another_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
another_socket.bind(('127.0.0.1', port))
another_socket.bind(('localhost', port))
except OSError as e:
assert 'Address already in use' in str(e)
return False
@ -93,6 +94,8 @@ class TestChannelArgument(AioTestBase):
random.seed(_RANDOM_SEED)
@unittest.skip('https://github.com/grpc/grpc/issues/20667')
@unittest.skipIf(platform.system() == 'Windows',
'SO_REUSEPORT only available in Linux-like OS.')
async def test_server_so_reuse_port_is_set_properly(self):
async def test_body():
@ -115,9 +118,11 @@ class TestChannelArgument(AioTestBase):
await asyncio.gather(*(test_body() for _ in range(_NUM_SERVER_CREATED)))
async def test_client(self):
# Do not segfault, or raise exception!
aio.insecure_channel('[::]:0', options=_TEST_CHANNEL_ARGS)
async def test_server(self):
# Do not segfault, or raise exception!
aio.server(options=_TEST_CHANNEL_ARGS)
async def test_invalid_client_args(self):

Loading…
Cancel
Save