From 026d0e6af68c92b0b9370ce5518a9925c190923c Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Mon, 28 Oct 2019 15:25:12 -0700 Subject: [PATCH] Incorporate review comments --- .../tests/unit/_metadata_flags_test.py | 2 +- .../tests/unit/_reconnect_test.py | 36 ++++++++++--------- .../grpcio_tests/tests/unit/test_common.py | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py b/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py index c2d2aa7c2e3..efc55ea2ddf 100644 --- a/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py +++ b/src/python/grpcio_tests/tests/unit/_metadata_flags_test.py @@ -228,7 +228,7 @@ class MetadataFlagsTest(unittest.TestCase): # Start the server after the connections are waiting wg.wait() - server = test_common.test_server() + server = test_common.test_server(reuse_port=True) server.add_generic_rpc_handlers((_GenericHandler( weakref.proxy(self)),)) server.add_insecure_port(addr) diff --git a/src/python/grpcio_tests/tests/unit/_reconnect_test.py b/src/python/grpcio_tests/tests/unit/_reconnect_test.py index 3861dee0265..8d7fd38868b 100644 --- a/src/python/grpcio_tests/tests/unit/_reconnect_test.py +++ b/src/python/grpcio_tests/tests/unit/_reconnect_test.py @@ -42,24 +42,26 @@ class ReconnectTest(unittest.TestCase): 'UnaryUnary': grpc.unary_unary_rpc_method_handler(_handle_unary_unary) }) - with bound_socket() as (_, port): - server = grpc.server(server_pool, (handler,)) - server.add_insecure_port('[::]:{}'.format(port)) + options=(('grpc.so_reuseport', 0),) + with bound_socket() as (host, port): + addr = '{}:{}'.format(host, port) + server = grpc.server(server_pool, (handler,), options=options) + server.add_insecure_port(addr) server.start() - channel = grpc.insecure_channel('localhost:%d' % port) - multi_callable = channel.unary_unary(_UNARY_UNARY) - self.assertEqual(_RESPONSE, multi_callable(_REQUEST)) - server.stop(None) - # By default, the channel connectivity is checked every 5s - # GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS can be set to change - # this. - time.sleep(5.1) - server = grpc.server(server_pool, (handler,)) - server.add_insecure_port('[::]:{}'.format(port)) - server.start() - self.assertEqual(_RESPONSE, multi_callable(_REQUEST)) - server.stop(None) - channel.close() + channel = grpc.insecure_channel(addr) + multi_callable = channel.unary_unary(_UNARY_UNARY) + self.assertEqual(_RESPONSE, multi_callable(_REQUEST)) + server.stop(None) + # By default, the channel connectivity is checked every 5s + # GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS can be set to change + # this. + time.sleep(5.1) + server = grpc.server(server_pool, (handler,), options=options) + server.add_insecure_port(addr) + server.start() + self.assertEqual(_RESPONSE, multi_callable(_REQUEST)) + server.stop(None) + channel.close() if __name__ == '__main__': diff --git a/src/python/grpcio_tests/tests/unit/test_common.py b/src/python/grpcio_tests/tests/unit/test_common.py index bc3b24862dc..305781bd533 100644 --- a/src/python/grpcio_tests/tests/unit/test_common.py +++ b/src/python/grpcio_tests/tests/unit/test_common.py @@ -100,14 +100,14 @@ def test_secure_channel(target, channel_credentials, server_host_override): return channel -def test_server(max_workers=10): +def test_server(max_workers=10, reuse_port=False): """Creates an insecure grpc server. These servers have SO_REUSEPORT disabled to prevent cross-talk. """ return grpc.server( futures.ThreadPoolExecutor(max_workers=max_workers), - options=(('grpc.so_reuseport', 0),)) + options=(('grpc.so_reuseport', int(reuse_port)),)) class WaitGroup(object):