Merge pull request #20790 from gnossen/metadata_flags_v6

Support both v4 and v6 in test
pull/20674/head
Richard Belleville 5 years ago committed by GitHub
commit e743d5e161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/python/grpcio_tests/tests/unit/_metadata_flags_test.py

@ -93,11 +93,29 @@ class _GenericHandler(grpc.GenericRpcHandler):
return None return None
def _create_socket_ipv6(bind_address):
listen_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
listen_socket.bind((bind_address, 0, 0, 0))
return listen_socket
def _create_socket_ipv4(bind_address):
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.bind((bind_address, 0))
return listen_socket
def get_free_loopback_tcp_port(): def get_free_loopback_tcp_port():
tcp = socket.socket(socket.AF_INET) listen_socket = None
tcp.bind(('', 0)) if socket.has_ipv6:
address_tuple = tcp.getsockname() try:
return tcp, "localhost:%s" % (address_tuple[1]) listen_socket = _create_socket_ipv6('')
except socket.error:
listen_socket = _create_socket_ipv4('')
else:
listen_socket = _create_socket_ipv4('')
address_tuple = listen_socket.getsockname()
return listen_socket, "localhost:%s" % (address_tuple[1])
def create_dummy_channel(): def create_dummy_channel():

Loading…
Cancel
Save